最近有項(xiàng)目的個別需求需要使用.net中的一些東西來實(shí)現(xiàn),如其中需要用到泛型集合List
忽然想起之前有小伙伴在群里也問過這個問題,當(dāng)時我好像給出了錯誤的答案,故總結(jié)一下順便糾正之前的錯誤。
看完這個激動不已,在System命名空間中通過Activator.CreateInstance 靜態(tài)方法進(jìn)行創(chuàng)建,在.net函數(shù)選板中找到Invoke Node,然后在右鍵菜單中找到“Select Class >> .NET >> Browse...”,如下圖所示:
在彈出的對話框中,找到Assembly選中mscorlib(4.0.0),并在下面的列表中找到System,如下圖所示:
雙擊展開System命名空間,找到Activator,如下圖所示:
然后鼠標(biāo)左鍵單擊Method,選擇CreateInstance(Type type),如下圖所示:
此時發(fā)現(xiàn)改方法需要傳入Type參數(shù),按圖索驥找到了System命名空間中的GetType(String)靜態(tài)方法,如下圖所示:
找到改靜態(tài)方法的方式同上述CreateInstance(Type type)一樣,這里不再贅述,如下圖所示:
此時發(fā)現(xiàn)改方法需要傳入typeName參數(shù),其實(shí)就是類型的程序集限定名稱,
文檔中給出了參考代碼,如下圖所示:
using System; using System.Collections.Generic; using System.Globalization; public class Example { public static void Main() { Type t = typeof(String); ShowTypeInfo(t); t = typeof(List<>); ShowTypeInfo(t); var list = new List(); t = list.GetType(); ShowTypeInfo(t); Object v = 12; t = v.GetType(); ShowTypeInfo(t); t = typeof(IFormatProvider); ShowTypeInfo(t); IFormatProvider ifmt = NumberFormatInfo.CurrentInfo; t = ifmt.GetType(); ShowTypeInfo(t); } private static void ShowTypeInfo(Type t) { Console.WriteLine($"Name: {t.Name}"); Console.WriteLine($"Full Name: {t.FullName}"); Console.WriteLine($"ToString: {t}"); Console.WriteLine($"Assembly Qualified Name: {t.AssemblyQualifiedName}"); Console.WriteLine(); } } // The example displays output like the following: // Name: String // Full Name: System.String // ToString: System.String // Assembly Qualified Name: System.String, mscorlib, Version=4.0.0.0, Culture=neutr // al, PublicKeyToken=b77a5c561934e089 // // Name: List`1 // Full Name: System.Collections.Generic.List`1 // ToString: System.Collections.Generic.List`1[T] // Assembly Qualified Name: System.Collections.Generic.List`1, mscorlib, Version=4. // 0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 // // Name: List`1 // Full Name: System.Collections.Generic.List`1[[System.String, mscorlib, Version=4 // .0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] // ToString: System.Collections.Generic.List`1[System.String] // Assembly Qualified Name: System.Collections.Generic.List`1[[System.String, mscor // lib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorl // ib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 // // Name: Int32 // Full Name: System.Int32 // ToString: System.Int32 // Assembly Qualified Name: System.Int32, mscorlib, Version=4.0.0.0, Culture=neutra // l, PublicKeyToken=b77a5c561934e089 // // Name: IFormatProvider // Full Name: System.IFormatProvider // ToString: System.IFormatProvider // Assembly Qualified Name: System.IFormatProvider, mscorlib, Version=4.0.0.0, Cult // ure=neutral, PublicKeyToken=b77a5c561934e089 // // Name: NumberFormatInfo // Full Name: System.Globalization.NumberFormatInfo // ToString: System.Globalization.NumberFormatInfo // Assembly Qualified Name: System.Globalization.NumberFormatInfo, mscorlib, Versio // n=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
我們在傳入改typeName參數(shù)時,傳入Full Name即可,如果你不知道你想創(chuàng)建的類型的Full Name可以先修改參考代碼并執(zhí)行,即可獲取。比如我想創(chuàng)建List
實(shí)際使用中我想創(chuàng)建的是List>對象,如下圖所示:
理解之后你就可以創(chuàng)建原本你以為無法創(chuàng)建的對象實(shí)例了。
審核編輯:劉清
-
LabVIEW
+關(guān)注
關(guān)注
1977文章
3657瀏覽量
325891
原文標(biāo)題:如何在LabVIEW中創(chuàng)建.net中的List
文章出處:【微信號:LabVIEW QT 修煉之路,微信公眾號:LabVIEW QT 修煉之路】歡迎添加關(guān)注!文章轉(zhuǎn)載請注明出處。
發(fā)布評論請先 登錄
相關(guān)推薦
在OrCAD中輕松創(chuàng)建并調(diào)整shape的操作步驟詳解
VC# .Net中瀏覽Crystal Report
labview中 list 列表實(shí)時讀取問題
在LABVIEW中 WORD型數(shù)據(jù)怎么表示,或怎么創(chuàng)建
labview中調(diào)用.net的richtextbox,當(dāng)內(nèi)容出現(xiàn)中文時,selectionstart不準(zhǔn)確的問題,請問怎么解決?
在ENV中配置硬件RTC+軟件RTC的步驟簡析
LabVIEW中調(diào)用DLL的高級技巧后續(xù)資源包
LabVIEW8.5中文評估版軟件安裝步驟
![<b class='flag-5'>LabVIEW</b>8.5<b class='flag-5'>中</b>文評估版軟件安裝<b class='flag-5'>步驟</b>](https://file1.elecfans.com//web2/M00/A5/82/wKgZomUMOMWARTMBAAElKUeo5ew796.jpg)
鼠標(biāo)HID例程(中)簡析
NANDFLASH在WINCE_NET系統(tǒng)中的應(yīng)用設(shè)計
![NANDFLASH<b class='flag-5'>在</b>WINCE_<b class='flag-5'>NET</b>系統(tǒng)<b class='flag-5'>中</b>的應(yīng)用設(shè)計](https://file.elecfans.com/web2/M00/4A/21/pYYBAGKhvJ2AP232AAAwambwods318.png)
LabVIEW中虛擬采集卡的創(chuàng)建教程資料說明
![<b class='flag-5'>LabVIEW</b><b class='flag-5'>中</b>虛擬采集卡的<b class='flag-5'>創(chuàng)建</b>教程資料說明](https://file.elecfans.com/web1/M00/82/9A/o4YBAFxBJg2AUwanAAHgIagTf5k481.png)
labview與sql數(shù)據(jù)庫連接5種方法
巖土工程監(jiān)測中振弦采集儀的布設(shè)方案及實(shí)施步驟簡析
![巖土工程監(jiān)測<b class='flag-5'>中</b>振弦采集儀的布設(shè)方案及實(shí)施<b class='flag-5'>步驟</b><b class='flag-5'>簡</b><b class='flag-5'>析</b>](https://file1.elecfans.com/web2/M00/8D/D4/wKgZomTAsDGAZv56AACDQIjQq_g000.png)
評論