如何名单< T>不执行添加(对象的值)? [英] how List<T> does not implement Add(object value)?
问题描述
我认为这是非常愚蠢的,我有点不好意思问这样的问题,但我还是没能找到答案:
我在看类列表< T>
,其中implemetns 的IList
<。 pre>
公共类List< T> :IList的
包括在IList中的方法之一是
INT加入(对象的值)
我明白了该列表< T>
不应该公开的方法(类型安全......),它真的没有。但是,怎么可能呢? ?mustnt类实现整个界面
我相信这(接口)方法的实施明确的:
公共类List< T> :IList的
{
INT IList.Add(对象的值){this.Add((T)值);}
}
这样的添加(对象)
方法将被隐藏。你只能够调用它,如果你投的列表< T>
实例回一个的IList
实例。
I believe it's pretty stupid, and I am a bit embarrassed to ask this kind of question, but I still could not find the answer:
I am looking at the class List<T>
, which implemetns IList
.
public class List<T> : IList
one of the methods included in Ilist is
int Add(object value)
I understand that List<T>
should not expose that method (type safety...), and it really does not. But how can it be? mustnt class implement the entire interface?
I believe that this (interface) method is implemented explicitly:
public class List<T> : IList
{
int IList.Add( object value ) {this.Add((T)value);}
}
By doing so, the Add( object )
method will by hidden. You'll only able to call it, if you cast the List<T>
instance back to an IList
instance.
这篇关于如何名单< T>不执行添加(对象的值)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!