问题描述
名单,其中的定义; T>
在.NET中显示它实现各种接口。
Definition of List<T>
in .net shows it implement various interfaces.
public class List<T> : IList<T>, ICollection<T>, IEnumerable<T>, IList, ICollection, IEnumerable
什么改变接口,使用和不使用 T
带来了的IList
也就是说,如果我班的一个实施的IList&LT; T&GT;
,而不是的IList
,那么我可以用它作为我的自定义集合类或不
What changes interfaces with and without T
brings in IList
i.e. if one of my class implement IList<T>
and not IList
, then can I use it as my custom collection class or not?
推荐答案
而之所以名单,其中,T&GT;
同时实现了的IList&LT; T&GT;
和的IList
是,以使其可在任何地方你code是假设一个的IList
。这将使其更容易做出普通的的IList℃的转变; T&GT;
,因为它是比较合适的。另外,如果你有一个.NET 1.1或更早版本的code,你想,即使你的类在.NET 2.0实现或更高版本组件就会使重用成为可能。
The reason that List<T>
implements both IList<T>
and IList
is to make it usable anywhere your code is assuming an IList
. This will make it more easier to make a transition to the generic IList<T>
since it is the more appropriate one. Also, if you have a .net 1.1 or earlier code that you would like to reuse even though your class is implemented in a .net 2.0 or later assembly it will make it possible.
这篇关于是的IList和IList中℃之间有什么区别; T&GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!