最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C#中Activator.CreateInstance()方法用法分析

 更新時間:2015年03月30日 15:43:01   作者:樂樂010  
這篇文章主要介紹了C#中Activator.CreateInstance()方法用法,實例分析了C#中Activator.CreateInstance()方法的功能、定義及使用技巧,需要的朋友可以參考下

本文實例講述了C#中Activator.CreateInstance()方法用法。分享給大家供大家參考。具體分析如下:

Activator 類

包含特定的方法,用以在本地或從遠程創(chuàng)建對象類型,或獲取對現(xiàn)有遠程對象的引用。

C#在類工廠中動態(tài)創(chuàng)建類的實例,所使用的方法為:

1. Activator.CreateInstance (Type)

2. Activator.CreateInstance (Type, Object[])

兩種方法區(qū)別僅為:創(chuàng)建無參數(shù)的構(gòu)造方法和創(chuàng)建有參數(shù)的構(gòu)造函數(shù)。

//Activator.CreateInstance(Type)
object result = null;
Type typeofControl =null;
typeofControl = Type.GetType(vFullClassName);
result = Activator.CreateInstance(typeofControl);
//Activator.CreateInstance(Type,Object[])
object result = null;
Type typeofControl =null;
typeofControl = Type.GetType(vFullClassName);
result = Activator.CreateInstance(typeofControl, objParam);

但是在動態(tài)創(chuàng)建時,可能會動態(tài)使用到外部應(yīng)用的DLL中類的實例,則此時需要進行反編譯操作,使用Reflection命名控件下的Assembly類。

//先使用Assembly類載入DLL,再根據(jù)類的全路徑獲取類

object result = null;
Type typeofControl = null;
Assembly tempAssembly;
tempAssembly = Assembly.LoadFrom(vDllName);
typeofControl = tempAssembly.GetType(vFullClassName);
result = Activator.CreateInstance(typeofControl, objParam);

希望本文所述對大家的C#程序設(shè)計有所幫助。

您可能感興趣的文章:

相關(guān)文章

最新評論

赤水市| 黎城县| 介休市| 辽中县| 安陆市| 庆城县| 棋牌| 绍兴县| 贵州省| 读书| 峨眉山市| 藁城市| 德钦县| 郴州市| 确山县| 通榆县| 宁晋县| 濉溪县| 田东县| 凌海市| 吉水县| 永和县| 三亚市| 宁武县| 云安县| 石家庄市| 碌曲县| 达拉特旗| 稻城县| 敦煌市| 定襄县| 乐陵市| 涟源市| 雷山县| 靖远县| 阳高县| 大埔区| 咸阳市| 大港区| 忻州市| 越西县|