我正在将应用程序从.NET 1.1迁移到.NET 2.0.我应该删除CollectionBase的所有用途吗?如果是这样,迁移的最佳策略是什么?
Mar*_*ram 22
是的,要查看的最佳类是在System.Collections.Generic中.
我通常使用List.
您可以使用两种方法:
一个
public class MyClass
{
public List<MyItem> Items;
}
Run Code Online (Sandbox Code Playgroud)
乙
public class MyItemCollection : List<MyItem>
{
}
public class MyClass
{
public MyItemCollection Items;
}
Run Code Online (Sandbox Code Playgroud)
这两种方法只是略有不同,如果您计划扩展List的功能,则只需要使用方法(B).
这是一个更多信息的链接:http:
//msdn.microsoft.com/en-us/library/6sh2ey19(VS.80).aspx
关于已经实现的类,可以删除IList接口中指定的所有函数.例如
public int Add(InstrumentTradeDataRow instTrade) { return List.Add(instTrade); }
Run Code Online (Sandbox Code Playgroud)
这可以删除,因为List已经为您实现了类型安全的Add功能.
有关更多信息,请参阅此链接:http:
//msdn.microsoft.com/en-us/library/3wcytfd1(VS.80).aspx
Mar*_*ell 16
通常,List<T>您通常需要的大部分内容.如果你想自定义行为,你应该继承Collection<T>- 这有virtual方法,所以你可以在添加/删除/更新等时调整行为.你不能这样做,List<T>因为没有(有害的)virtual方法.