C#学习笔记之类型基础
一、类型转换:
CLR允许我们将对象转换为其原来的类型或者它的任何一个基类型。转换为基类型被认为是安全的隐式操作。但是C#在将对象转换为它的任何派生类型时,要求进行显式转型。
二、使用is和as操作符转型:
A.利用is操作符进行转型,可以检查对象是否和给定的类型兼容,并返回判断结果:true或false.(is操作永远不会抛出异常)




B.as操作符在简化代码的同时提高性能:
C.is与as操作符的比较:














三、命名空间与程序集:
命名空间与程序集之间并没有必然的联系。
多个属于同一命名空间的类型可能被实现在多个程序集中。例如:System.IO.FileStream类型被实现在MSCorLib.dll程序集中,而System.IO.FileSystemWatcher类型被实现在System.dll程序集中。
一个程序集也可以包含位于不同命名空间中的类型。如:System.Int32和System.Collection.ArrayList类型都位于MSCorLib.dll程序集中。