随笔分类 -  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 阅读全文
posted @ 2011-07-18 15:21 绯色卡卡 阅读(144) 评论(0) 推荐(0)
摘要: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()。 阅读全文
posted @ 2011-07-18 11:47 绯色卡卡 阅读(113) 评论(0) 推荐(0)
摘要:<operand> is <type>检查对象是否是给定的类型,或者是否可以转换为给定的类型。 阅读全文
posted @ 2011-07-18 11:35 绯色卡卡 阅读(123) 评论(0) 推荐(0)
摘要:MyClass mc1 = new MyClass();object mc2 = mc1;也可以把对象封为接口 阅读全文
posted @ 2011-07-18 11:02 绯色卡卡 阅读(264) 评论(0) 推荐(0)
摘要:实现ICloneable接口public class MyClass : ICloneable{ public object Clone() { ... return ...; }} 阅读全文
posted @ 2011-07-18 10:50 绯色卡卡 阅读(137) 评论(0) 推荐(0)
摘要:public partial class MyClass{ ...}可以把一个类定义在多处 阅读全文
posted @ 2011-07-18 09:12 绯色卡卡 阅读(124) 评论(0) 推荐(0)
摘要:隐藏基接口,使用new关键字interface IMyBaseInterface{ void DoSomething();}interface IMyDerivedInterface : IMyBaseInterface{ new void DoSomething();}在接口中定义的属性可以定义get和set哪一个可以访问interface IMyInterface{ int MyInt { get; set; }} 阅读全文
posted @ 2011-07-18 09:04 绯色卡卡 阅读(106) 评论(0) 推荐(0)
摘要:在继承类中用new关键字声明与基类同名的方法可以隐藏父类的方法base调用基类,相当于Java里的superthis调用当前对象,相当于Java里的this 阅读全文
posted @ 2011-07-15 17:23 绯色卡卡 阅读(268) 评论(0) 推荐(0)
摘要:定义字段readonly 字段只能在执行构造函数的过程中赋值,或者由初始化赋值语句赋值定义方法virtual 方法可以重写abstract 方法必须在非抽象的派生类中重写(只用于抽象类中)override 方法重写了一个基类方法(如果方法被重写,就必须使用该关键字)extern 方法定义放在其他地方定义属性private int myInt;Public int MyIntProp{ get { return myInt; } set { myInt = value; }} 阅读全文
posted @ 2011-07-15 16:47 绯色卡卡 阅读(223) 评论(0) 推荐(0)
摘要:public MyClass():base(5){}public MyClass:this(5,6){} 阅读全文
posted @ 2011-07-15 14:19 绯色卡卡 阅读(106) 评论(0) 推荐(0)
摘要:ClassName myClass = new ClassName();using(myClass){}变量myClass可以在using代码块内使用,并在代码块的末尾自动删除。 阅读全文
posted @ 2011-07-15 11:08 绯色卡卡 阅读(207) 评论(0) 推荐(0)
摘要:delegate double ProcessDelegate(double param1,double param2);ProcessDelegate process;process = new ProcessDelegate(divide);process(param1,param2);委托可以作为参数传递给函数 阅读全文
posted @ 2011-07-15 09:46 绯色卡卡 阅读(117) 评论(0) 推荐(0)
摘要:static void showDouble(ref int val){ val *= 2; Console.WriteLine("val double = {0}",val);}调用时变量名前也要加上 refref参数限制1.不可以为const2.必须初始化若未赋值,使用out参数 阅读全文
posted @ 2011-07-14 11:49 绯色卡卡 阅读(142) 评论(0) 推荐(0)
摘要:矩形数组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}}; 阅读全文
posted @ 2011-07-13 17:28 绯色卡卡 阅读(105) 评论(0) 推荐(0)
摘要:foreach(string friendName in friendNames){ Console.WriteLine(friendName);}只读访问 阅读全文
posted @ 2011-07-13 17:12 绯色卡卡 阅读(166) 评论(0) 推荐(0)
摘要:checked(); 检查溢出unchecked(); 不检查溢出 阅读全文
posted @ 2011-07-13 16:19 绯色卡卡 阅读(111) 评论(0) 推荐(0)
摘要:#region Your Block Namecode...code...code...#endregion 阅读全文
posted @ 2011-07-13 11:16 绯色卡卡 阅读(1034) 评论(0) 推荐(1)