1.as关键字
2.is关键字
3.参考资料和代码下载
使用as关键字的表达式的一般情景是:obj as type,该表达式返回的是type指定的类型或者是null。简单的测试代码如下:
class AsTest
{
public static void DoTest()
{
string obj1 = "as1";
object obj2 = "as2";
string obj3 = obj2 as string;
if (obj3 != null)
{
Console.WriteLine("obj2 is a string type!");
}
}
}
{
public static void DoTest()
{
string obj1 = "as1";
object obj2 = "as2";
string obj3 = obj2 as string;
if (obj3 != null)
{
Console.WriteLine("obj2 is a string type!");
}
}
}