usingSystem;namespaceConsoleApp1{classProgram{staticvoidMain(string[] args){Program program =newProgram();
program.MyMethod();
program.MyMethod2();
program.MyMethod3(1,"123");int a =50;
program.MyMethod4(ref a);print(a);int b;
program.MyMethod5(out b);print(b);
Console.ReadKey();}publicstaticvoidprint(object obj){
Console.WriteLine(obj);}publicvoidMyMethod(){
Console.WriteLine("我是一个自定义方法");}publicintMyMethod2(){return20;}publicvoidMyMethod3(int a,string b){
Console.WriteLine(a);
Console.WriteLine(b);}publicvoidMyMethod4(refint a){
a +=10;}publicvoidMyMethod5(outint a){
a =10;
a -=5;}}}
空
usingSystem;namespaceConsoleApp2{classProgram{staticvoidMain(string[] args){//第一种方式Nullable<short> na =null;//第二种方式int? a =null;//双问号的使用int c = a ??10;print(a);print(c);}publicstaticvoidprint(object obj){
Console.WriteLine(obj);}}}
string a ="hello world";string b ="hello";//a包含bprint(a.Contains(b));//a相同bprint(a.Equals(b));//a以b开头print(a.StartsWith(b));//a以b结束print(a.EndsWith(b));//返回下标print(a.IndexOf("wo"));//格式替换string c ="hello{0} world{1}";print(string.Format(c,"你好","世界"));