您的位置:首页 > 其它

反射的一个实例

2007-07-29 21:22 197 查看
下面是使用静态方法 GetType-- 从 Object 基类派生的所有类型都继承该方法 --
获取变量类型的简单反射示例:

C#



// Using GetType to obtain type information:
int i = 42;
System.Type type = i.GetType();
System.Console.WriteLine(type);


输出为:

System.Int32

此示例使用反射获取已加载的程序集的完整名称:

// Using Reflection to get information from an Assembly:
System.Reflection.Assembly o = System.Reflection.Assembly.Load("mscorlib.dll");
System.Console.WriteLine(o.GetName());
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: