Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# IList上的索引器_C#_Oop_Inheritance - Fatal编程技术网

C# IList上的索引器

C# IList上的索引器,c#,oop,inheritance,C#,Oop,Inheritance,这可能是我在C#继承中忽略的一点,但我试图构建一个实现IList(System.Collections版本,而不是泛型)的类编译器抱怨我没有实现索引器,但我正在查看同样实现IList的CollectionBase,它似乎也没有公开索引器 从Reflector的角度来看,CollectionBase似乎是抽象的,它确实实现了一个索引器,但它似乎是私有的。我尝试了这一点,但没有掷骰子,编译器坚持认为,如果我想实现IList,我必须有一个返回对象的公共、非静态索引器 因此,我的问题不是为什么我需要一个

这可能是我在C#继承中忽略的一点,但我试图构建一个实现IList(System.Collections版本,而不是泛型)的类编译器抱怨我没有实现索引器,但我正在查看同样实现IList的CollectionBase,它似乎也没有公开索引器

从Reflector的角度来看,CollectionBase似乎是抽象的,它确实实现了一个索引器,但它似乎是私有的。我尝试了这一点,但没有掷骰子,编译器坚持认为,如果我想实现IList,我必须有一个返回对象的公共、非静态索引器


因此,我的问题不是为什么我需要一个,而是CollectionBase如何使用私有索引器?

它没有-它使用显式接口实现:

对象IList.this[int index]{get;set;}


它就在那里,你只是在默认的类接口上看不到它(使用COM术语)-你必须转换到IList才能看到/使用它。

啊,好的,谢谢。我总是忘记显式继承。有时我想知道它是否只是为了避免多重继承和名称冲突。