程序一生

博客园 首页 新随笔 联系 订阅 管理

public static Type GetType(string); 与Activator.CreateInstance(System.Type.GetType(string))使用方法

public static Type GetType(string)
其中string为命名空间加类型名


Activator.CreateInstance(System.Type.GetType(string))

使用与指定参数匹配程度最高的构造函数创建指定类型的实例。

------------------------------------------------------------------------------------------------------

const与static readonly的使用方法与区别
const的值是在编译期间确定的,因此只能在声明时通过常量表达式指定其值。而static readonly是在运行时计算出其值的,所以还可以通过静态构造函数来赋值。

如果static readonly声明的是引用类型,则它只是被限定不能进行赋值(写)操作而已。而对其成员的读写仍然是不受限制的
public static readonly MyClass myins = new MyClass();

myins.SomeProperty = 10;  //正常
myins = new MyClass();    //出错,该对象是只读的

但是,如果上例中的MyClass不是一个class而是一个struct,那么后面的两个语句就都会出错。


-------------------------------------------------------------------------------------------------------
事件与委托
自定义事件,事件订阅


posted on 2005-12-19 15:44  网风   阅读(250)  评论(0)    收藏  举报