欢迎来到天天文库
浏览记录
ID:11998896
大小:270.00 KB
页数:49页
时间:2018-07-15
《c#程序设计编程实例大全》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、C#程序设计编程实例大全usingSystem;classhello{staticvoidMain(){Console.WriteLine("HelloWorld");}}usingSystem;classTest{staticvoidMain(){//int[]arr=newint[]{1,2,3};int[]arr={1,2,3};for(inti=0;i2、){for(inti=0;i<256;i++){if(i%10==0){Console.WriteLine();}Console.WriteLine("{0,3}:{1,-3}",i,(char)i);}}}usingSystem;abstractclassA{protectedint_x;publicabstractvoidF();publicabstractintX{get;set;}}classB:A{publicoverridevoidF(){}publicoverrideintX{get{return_x;}3、set{_x=value;}}}classTest{staticvoidMain(){Bb=newB();b.X=10;Console.WriteLine(b.X);}}usingSystem;structMyClass{publicinti;}classTest{staticvoidSeti(MyClassm){m.i=300;}staticvoidMain(){MyClassmc=newMyClass();mc.i=100;MyClassmc1=mc;Seti(mc1);Console.WriteLine("mc.4、i="+mc.i);Console.WriteLine("mc1.i="+mc1.i);}}usingSystem;classmethod{staticvoidMain(){inti=5;intj=3;Console.WriteLine("i+j="+add(i,j));}publicstaticintadd(inti,intj){returni+j;}}usingSystem;usingSystem.Windows.Forms;classFruit{}classApple:Fruit{publicinti=1;}cl5、assConversions{staticvoidMain(){//Fruitf=newApple();//Typet=f.GetType();//Applea=(Apple)f;//Console.WriteLine(a.i);//Console.WriteLine(((Apple)f).i);//Fruitf=newFruit();//Applea=newApple();//Console.WriteLine(fisFruit);//Console.WriteLine(fisApple);//Console.Wri6、teLine(aisFruit);//Console.WriteLine(aisApple);/*Fruitf=newApple();if(fisApple){Applea=(Apple)f;Console.WriteLine(a.i);}*/Fruitf=newApple();Applea=fasApple;if(a!=null){Console.WriteLine(a.i);}}}usingSystem;usingSystem.Collections;classArrList{staticvoidMain(){Ar7、rayListarr=newArrayList();stringstr1;while(true){Console.WriteLine("PleaseaddastringtotheArrayList:");str1=Console.ReadLine();if(str1=="end")break;arr.Add(str1);Console.WriteLine();for(inti=0;i8、}usingSystem;classA{publicA(){Console.WriteLine("我是A类的无参构造函数");}publicA(inti){Console.WriteLine("我是类A的带有一个参数的构造函数");}}classB:A{publicB(){Console.WriteLine("我是B类的无参构造函
2、){for(inti=0;i<256;i++){if(i%10==0){Console.WriteLine();}Console.WriteLine("{0,3}:{1,-3}",i,(char)i);}}}usingSystem;abstractclassA{protectedint_x;publicabstractvoidF();publicabstractintX{get;set;}}classB:A{publicoverridevoidF(){}publicoverrideintX{get{return_x;}
3、set{_x=value;}}}classTest{staticvoidMain(){Bb=newB();b.X=10;Console.WriteLine(b.X);}}usingSystem;structMyClass{publicinti;}classTest{staticvoidSeti(MyClassm){m.i=300;}staticvoidMain(){MyClassmc=newMyClass();mc.i=100;MyClassmc1=mc;Seti(mc1);Console.WriteLine("mc.
4、i="+mc.i);Console.WriteLine("mc1.i="+mc1.i);}}usingSystem;classmethod{staticvoidMain(){inti=5;intj=3;Console.WriteLine("i+j="+add(i,j));}publicstaticintadd(inti,intj){returni+j;}}usingSystem;usingSystem.Windows.Forms;classFruit{}classApple:Fruit{publicinti=1;}cl
5、assConversions{staticvoidMain(){//Fruitf=newApple();//Typet=f.GetType();//Applea=(Apple)f;//Console.WriteLine(a.i);//Console.WriteLine(((Apple)f).i);//Fruitf=newFruit();//Applea=newApple();//Console.WriteLine(fisFruit);//Console.WriteLine(fisApple);//Console.Wri
6、teLine(aisFruit);//Console.WriteLine(aisApple);/*Fruitf=newApple();if(fisApple){Applea=(Apple)f;Console.WriteLine(a.i);}*/Fruitf=newApple();Applea=fasApple;if(a!=null){Console.WriteLine(a.i);}}}usingSystem;usingSystem.Collections;classArrList{staticvoidMain(){Ar
7、rayListarr=newArrayList();stringstr1;while(true){Console.WriteLine("PleaseaddastringtotheArrayList:");str1=Console.ReadLine();if(str1=="end")break;arr.Add(str1);Console.WriteLine();for(inti=0;i8、}usingSystem;classA{publicA(){Console.WriteLine("我是A类的无参构造函数");}publicA(inti){Console.WriteLine("我是类A的带有一个参数的构造函数");}}classB:A{publicB(){Console.WriteLine("我是B类的无参构造函
8、}usingSystem;classA{publicA(){Console.WriteLine("我是A类的无参构造函数");}publicA(inti){Console.WriteLine("我是类A的带有一个参数的构造函数");}}classB:A{publicB(){Console.WriteLine("我是B类的无参构造函
此文档下载收益归作者所有