C# 调用 Microsoft.VisualBasic.Collection
生活随笔
收集整理的這篇文章主要介紹了
C# 调用 Microsoft.VisualBasic.Collection
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
問題
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("?個")?
For?Each?aa?As?String?In?t?
sb.AppendLine()?
sb.Append(aa)?
Next?
End?If?
MsgBox(sb.ToString)?
以上是使用ARRAYLIST存儲一個集合,VB中可以使用collectin,將其傳入arraylist,而在C#中如何定義這個東西,使他能夠傳入ARRAYLIST呢?給個例子,謝謝 http://community.csdn.net/Expert/TopicView3.asp?id=5655091
解決
1。
//?事實上你可以直接在?C#?中使用?Microsoft.VisualBasic.Collection
//?需要添加對?Microsoft.VisualBasic.dll?的引用
Microsoft.VisualBasic.Collection?d?=?new?Microsoft.VisualBasic.Collection();
d.Add("Northsnow",?null,?null,?null);?//?C#?不支持可選參數,?若不指定?傳入?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("?個");
}
foreach?(string?aa?in?t)?{
sb.AppendLine();
sb.Append(aa);
}
2。
以上代碼比較適合將進行?VB.net?向?C#?的直接移植,
因為
Visual?Basic?集合與?System.Collections、System.Collections.Generic?和?System.Collections.Specialized?命名空間中的?.NET?Framework?集合不兼容
具體沒有實踐過,不知道是否會導致后期維護的困難。
3。
若新項目,最佳實踐實現是,使用?System.Collection.ArrayList
ArrayList?list1?=?new?ArrayList();
list1.Add("a");
list1.Add("b");
ArrayList?list2?=?new?ArrayList(list1);
補充
????????//?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("?個")?
For?Each?aa?As?String?In?t?
sb.AppendLine()?
sb.Append(aa)?
Next?
End?If?
MsgBox(sb.ToString)?
以上是使用ARRAYLIST存儲一個集合,VB中可以使用collectin,將其傳入arraylist,而在C#中如何定義這個東西,使他能夠傳入ARRAYLIST呢?給個例子,謝謝 http://community.csdn.net/Expert/TopicView3.asp?id=5655091
解決
1。
//?事實上你可以直接在?C#?中使用?Microsoft.VisualBasic.Collection
//?需要添加對?Microsoft.VisualBasic.dll?的引用
Microsoft.VisualBasic.Collection?d?=?new?Microsoft.VisualBasic.Collection();
d.Add("Northsnow",?null,?null,?null);?//?C#?不支持可選參數,?若不指定?傳入?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("?個");
}
foreach?(string?aa?in?t)?{
sb.AppendLine();
sb.Append(aa);
}
2。
以上代碼比較適合將進行?VB.net?向?C#?的直接移植,
因為
Visual?Basic?集合與?System.Collections、System.Collections.Generic?和?System.Collections.Specialized?命名空間中的?.NET?Framework?集合不兼容
具體沒有實踐過,不知道是否會導致后期維護的困難。
3。
若新項目,最佳實踐實現是,使用?System.Collection.ArrayList
ArrayList?list1?=?new?ArrayList();
list1.Add("a");
list1.Add("b");
ArrayList?list2?=?new?ArrayList(list1);
補充
?
//?對于?.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
總結
1. .NET? 果然跨語言^_^
2. 由于語言特性本身的差異,需要注意對特定語法支持,特別是開發類庫的時候
3. 為保證語言的兼容性和互操作性,盡可能選擇非特定語言支持的類庫,而使用 System 命名空間及其子命名空間的類
轉載于:https://www.cnblogs.com/Jinglecat/archive/2007/07/17/821824.html
總結
以上是生活随笔為你收集整理的C# 调用 Microsoft.VisualBasic.Collection的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 装饰模式在Intermec CK1应用程
- 下一篇: asp.net MD5加密函数(c#)