CollectionBase的VS仿制药 [英] CollectionBase vs generics

查看:158
本文介绍了CollectionBase的VS仿制药的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我迁移从.NET 1.1的应用程序到.NET 2.0。我应该删除CollectionBase中的所有用途?如果是这样,什么是迁移的最佳策略是什么?

I am migrating an application from .NET 1.1 to .NET 2.0. Should I remove all uses of CollectionBase? If so, what is the best strategy for migration?

推荐答案

是的,最好的类来看看在System.Collections.Generic。
我通常用列表。

Yes, the best classes to look at are in System.Collections.Generic.
I usually use List.

有两种方法,你可以使用:

There are two approaches you can use either:

A

public class MyClass
{
  public List<MyItem> Items;
}

B

public class MyItemCollection : List<MyItem>
{
}

public class MyClass
{
  public MyItemCollection Items;
}

这两种方法只是略微不同,你只需要使用方法(二)如果你打算扩展列表的功能。

The two approaches only differ very slightly and you only need to use method (B) if you plan on extending the functionality of List.

下面是更多的信息链接:
<一href="http://msdn.microsoft.com/en-us/library/6sh2ey19">http://msdn.microsoft.com/en-us/library/6sh2ey19(VS.80).aspx

Here's a link with more info:
http://msdn.microsoft.com/en-us/library/6sh2ey19(VS.80).aspx

至于你已经实现了类,你可以删除所有的这些都在IList接口指定的功能。例如,

With regards to the classes that you've already implemented, you can remove all of the functions which are specified in the IList interface. e.g.

public int Add(InstrumentTradeDataRow instTrade) { return List.Add(instTrade); }

由于清单已经实现了一种安全的添加功能,你可以去掉这个。

This can be removed because List already implements a type safe Add function for you.

请参阅此链接了解更多信息:
<一href="http://msdn.microsoft.com/en-us/library/3wcytfd1">http://msdn.microsoft.com/en-us/library/3wcytfd1(VS.80).aspx

See this link for more information:
http://msdn.microsoft.com/en-us/library/3wcytfd1(VS.80).aspx

这篇关于CollectionBase的VS仿制药的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆