typeof,gettype,is,as
public class testclass
{
public string s = "";
public int i = 0;
}
testclass o = new testclass();
System.Type t1 = typeof(testclass);
System.Type t2 = o.GetType();
if (o is testclass)
{
MessageBox.Show("o is testclass");
}
object b = o as object;
if(b.GetType() is System.Type)
{
MessageBox.Show("b.GetType() is testclass");
}
typeof(类型)得到System.Type
实例.gettype()得到System.Type
is: if(实例 is 类型)
as 转型
浙公网安备 33010602011771号