Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何在接口中定义索引器方法?
您可以使用索引器定义接口,如下所示:
public interface Foo { int this[int i] { get; set; } }
现在任何实现此接口的类都需要定义一个带有 getter 和 setter 的索引器。接口不能定义索引器的实现;它只能要求实现接口的类来定义一个。