随笔分类 - C#
摘要:public class ConvClass1{ public int val; public static implicit operator ConvClass2(ConvClass1 op1) { ConvClass2 returnVal = new ConvClass2(); returnVal.val = op1.val; return returnVal; }}public class ConvClass2{ publicdouble val; public static explicit operator ConvClass1(ConvClass2 op1) { ConvClas
阅读全文
摘要:public class AddClass1{ public int val; public static AddClass1 operator +(AddClass op1,AddClass op2) { AddClass1 returnVal = new AddClass1(); returnVal.val = op1.val+op2.val; return returnVal; }}重写Object.Equals()和Object.GetHashCode()。
阅读全文
摘要:<operand> is <type>检查对象是否是给定的类型,或者是否可以转换为给定的类型。
阅读全文
摘要:MyClass mc1 = new MyClass();object mc2 = mc1;也可以把对象封为接口
阅读全文
摘要:实现ICloneable接口public class MyClass : ICloneable{ public object Clone() { ... return ...; }}
阅读全文
摘要:public partial class MyClass{ ...}可以把一个类定义在多处
阅读全文
摘要:隐藏基接口,使用new关键字interface IMyBaseInterface{ void DoSomething();}interface IMyDerivedInterface : IMyBaseInterface{ new void DoSomething();}在接口中定义的属性可以定义get和set哪一个可以访问interface IMyInterface{ int MyInt { get; set; }}
阅读全文
摘要:在继承类中用new关键字声明与基类同名的方法可以隐藏父类的方法base调用基类,相当于Java里的superthis调用当前对象,相当于Java里的this
阅读全文
摘要:定义字段readonly 字段只能在执行构造函数的过程中赋值,或者由初始化赋值语句赋值定义方法virtual 方法可以重写abstract 方法必须在非抽象的派生类中重写(只用于抽象类中)override 方法重写了一个基类方法(如果方法被重写,就必须使用该关键字)extern 方法定义放在其他地方定义属性private int myInt;Public int MyIntProp{ get { return myInt; } set { myInt = value; }}
阅读全文
摘要:public MyClass():base(5){}public MyClass:this(5,6){}
阅读全文
摘要:ClassName myClass = new ClassName();using(myClass){}变量myClass可以在using代码块内使用,并在代码块的末尾自动删除。
阅读全文
摘要:delegate double ProcessDelegate(double param1,double param2);ProcessDelegate process;process = new ProcessDelegate(divide);process(param1,param2);委托可以作为参数传递给函数
阅读全文
摘要:static void showDouble(ref int val){ val *= 2; Console.WriteLine("val double = {0}",val);}调用时变量名前也要加上 refref参数限制1.不可以为const2.必须初始化若未赋值,使用out参数
阅读全文
摘要:矩形数组int array[,] = new int[3,4];int array[,] = {{1,2,3,4},{2,3,4,5},{3,4,5,6}};变长数组int[][] array = new int[2][];array[0] = new int[3];array[1] = new int[4];int[][] array = {new int[]{1,2,3},new int[] {1},new int[]{1,2}};
阅读全文
摘要:foreach(string friendName in friendNames){ Console.WriteLine(friendName);}只读访问
阅读全文
摘要:#region Your Block Namecode...code...code...#endregion
阅读全文

浙公网安备 33010602011771号