IS & AS

obj is Employee

obj as Employee

checked & unchecked

checked((byte)(b+200))

checked
{
   
byte b = 100;
   b 
= (byte) (b + 200);
   SomeMethod(
400); // 在checked操作符或语句内调用一个方法并不会对该方法产生任何影响
}

 值类型与引用类型

 

Equal,GetHashCode,拷贝

重写Equal方法的同时必须重写GetHashCode方法,因为Hashtable要求相等的两个对象拥有相同的HashCode;

Obj.MemberwiseClone()是浅拷贝;

 

有参属性(索引):

public bool this[int index]
{
    
get{}
    
set{}
}

 

Char

有三种技巧允许我们进行Char和数值之间的转化:

//直接转化,性能最好
Char c = (Char)65;
int i = (int)c;
//Convert
Char c = Convert.ToChar(65);
int i = Convert.ToInt(c);
//IConvertable
Char c = ((IConvertable)65).ToChar(null);
int i = ((IConvertable)c).ToInt(null);

相关文章: