c#4.0笔记
1.值类型:数据存放在栈中;引用类型:实际数据存在在堆中,引用存放在栈中
2.类是逻辑相关的数据和函数的封装,通常代表真实世界或概念上的事物
3.字段是数据成员,方法是函数成员
4.private私有的,Public 共有的,internal内部的,protected受保护的,protected internal 内部受保护的
5.c#4.0开始可以震源待用参数:方法:static void Method(int a, int b,int c)
调用方式:Method(c:3,b:2,a:1)
6.在类的继承中,可访问父类公共成员,同时也可以重载方法,同时也可以使用关键new隐藏父类中的成员
View Code
1 class SomeClass 2 { 3 public string file1 = "这是第一个"; 4 public void Method1(string value) 5 { 6 Console.WriteLine(value); 7 } 8 } 9 class OtherClass : SomeClass 10 { 11 public string file2 = "这是第二个"; 12 new public string file1 = "这是隐藏"; 13 public void Method1(string value,string name) 14 { 15 Console.WriteLine(value+name); 16 } 17 } 18 class Program 19 { 20 static void Main(string[] args) 21 { 22 OtherClass o = new OtherClass(); 23 o.Method1(o.file1); 24 o.Method1(o.file2); 25 o.Method1(o.file1,o.file2); 26 Console.ReadLine(); 27 } 28 }
7.虚方法和覆写方法 virtual public void Methid() override public void Method()
8.(abstract)抽象类是被设计来继承的,只能用作其他类的基类,不能实例化,但抽象类和继承抽象类
9.在强制类型转换中,Int32.Parse()优于Convert.Int32()


浙公网安备 33010602011771号