C# 调用 Microsoft.VisualBasic.Collection
生活随笔
收集整理的這篇文章主要介紹了
C# 调用 Microsoft.VisualBasic.Collection
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
問題
Dim?d?As?New?Collection?
d.Add("Northsnow")?
d.Add("塞北的雪")?
d.Add("http://blog.csdn.net")?
Dim?t?As?New?ArrayList(d)?
Dim?sb?As?New?System.Text.StringBuilder()?
If?t.Count?>?0?Then?
sb.Append("ArrayList中共有?成員?")?
sb.Append(t.Item(2).ToString)?
sb.Append("?個(gè)")?
For?Each?aa?As?String?In?t?
sb.AppendLine()?
sb.Append(aa)?
Next?
End?If?
MsgBox(sb.ToString)?
以上是使用ARRAYLIST存儲(chǔ)一個(gè)集合,VB中可以使用collectin,將其傳入arraylist,而在C#中如何定義這個(gè)東西,使他能夠傳入ARRAYLIST呢?給個(gè)例子,謝謝 http://community.csdn.net/Expert/TopicView3.asp?id=5655091
解決
1。
//?事實(shí)上你可以直接在?C#?中使用?Microsoft.VisualBasic.Collection
//?需要添加對(duì)?Microsoft.VisualBasic.dll?的引用
Microsoft.VisualBasic.Collection?d?=?new?Microsoft.VisualBasic.Collection();
d.Add("Northsnow",?null,?null,?null);?//?C#?不支持可選參數(shù),?若不指定?傳入?null
d.Add("塞北的雪",?null,?null,?null);
d.Add("http://blog.csdn.net",?null,?null,?null);
ArrayList?t?=?new?ArrayList(d);
StringBuilder?sb?=?new?System.Text.StringBuilder();
if?(t.Count?>?0)?{
sb.Append("ArrayList中共有?成員?");
sb.Append(t.Count.ToString());
sb.Append("?個(gè)");
}
foreach?(string?aa?in?t)?{
sb.AppendLine();
sb.Append(aa);
}
2。
以上代碼比較適合將進(jìn)行?VB.net?向?C#?的直接移植,
因?yàn)?br />
Visual?Basic?集合與?System.Collections、System.Collections.Generic?和?System.Collections.Specialized?命名空間中的?.NET?Framework?集合不兼容
具體沒有實(shí)踐過,不知道是否會(huì)導(dǎo)致后期維護(hù)的困難。
3。
若新項(xiàng)目,最佳實(shí)踐實(shí)現(xiàn)是,使用?System.Collection.ArrayList
ArrayList?list1?=?new?ArrayList();
list1.Add("a");
list1.Add("b");
ArrayList?list2?=?new?ArrayList(list1);
補(bǔ)充
????????//?using?System.Collections.Generic;
????????IList<int>?list2?=?new?List<int>(2);
????????list2.Add(119);
????????list2.Add(911);
????????//?
Dim?d?As?New?Collection?
d.Add("Northsnow")?
d.Add("塞北的雪")?
d.Add("http://blog.csdn.net")?
Dim?t?As?New?ArrayList(d)?
Dim?sb?As?New?System.Text.StringBuilder()?
If?t.Count?>?0?Then?
sb.Append("ArrayList中共有?成員?")?
sb.Append(t.Item(2).ToString)?
sb.Append("?個(gè)")?
For?Each?aa?As?String?In?t?
sb.AppendLine()?
sb.Append(aa)?
Next?
End?If?
MsgBox(sb.ToString)?
以上是使用ARRAYLIST存儲(chǔ)一個(gè)集合,VB中可以使用collectin,將其傳入arraylist,而在C#中如何定義這個(gè)東西,使他能夠傳入ARRAYLIST呢?給個(gè)例子,謝謝 http://community.csdn.net/Expert/TopicView3.asp?id=5655091
解決
1。
//?事實(shí)上你可以直接在?C#?中使用?Microsoft.VisualBasic.Collection
//?需要添加對(duì)?Microsoft.VisualBasic.dll?的引用
Microsoft.VisualBasic.Collection?d?=?new?Microsoft.VisualBasic.Collection();
d.Add("Northsnow",?null,?null,?null);?//?C#?不支持可選參數(shù),?若不指定?傳入?null
d.Add("塞北的雪",?null,?null,?null);
d.Add("http://blog.csdn.net",?null,?null,?null);
ArrayList?t?=?new?ArrayList(d);
StringBuilder?sb?=?new?System.Text.StringBuilder();
if?(t.Count?>?0)?{
sb.Append("ArrayList中共有?成員?");
sb.Append(t.Count.ToString());
sb.Append("?個(gè)");
}
foreach?(string?aa?in?t)?{
sb.AppendLine();
sb.Append(aa);
}
2。
以上代碼比較適合將進(jìn)行?VB.net?向?C#?的直接移植,
因?yàn)?br />
Visual?Basic?集合與?System.Collections、System.Collections.Generic?和?System.Collections.Specialized?命名空間中的?.NET?Framework?集合不兼容
具體沒有實(shí)踐過,不知道是否會(huì)導(dǎo)致后期維護(hù)的困難。
3。
若新項(xiàng)目,最佳實(shí)踐實(shí)現(xiàn)是,使用?System.Collection.ArrayList
ArrayList?list1?=?new?ArrayList();
list1.Add("a");
list1.Add("b");
ArrayList?list2?=?new?ArrayList(list1);
補(bǔ)充
?
//?對(duì)于?.net?2.0?最佳還是選擇泛型版本的?List????????//?using?System.Collections.Generic;
????????IList<int>?list2?=?new?List<int>(2);
????????list2.Add(119);
????????list2.Add(911);
????????//?
Visual Basic Collection 類 http://msdn2.microsoft.com/zh-cn/library/microsoft.visualbasic.collection(VS.80).aspx
總結(jié)
1. .NET? 果然跨語言^_^
2. 由于語言特性本身的差異,需要注意對(duì)特定語法支持,特別是開發(fā)類庫(kù)的時(shí)候
3. 為保證語言的兼容性和互操作性,盡可能選擇非特定語言支持的類庫(kù),而使用 System 命名空間及其子命名空間的類
轉(zhuǎn)載于:https://www.cnblogs.com/Jinglecat/archive/2007/07/17/821824.html
總結(jié)
以上是生活随笔為你收集整理的C# 调用 Microsoft.VisualBasic.Collection的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 装饰模式在Intermec CK1应用程
- 下一篇: asp.net MD5加密函数(c#)