实现 IList 接口 [英] Implementing IList interface

查看:27
本文介绍了实现 IList 接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是泛型的新手.我想通过从 IList 接口派生它来实现我自己的集合.

I am new to generics. I want to implement my own collection by deriving it from IList<T> interface.

能否请您提供一些指向实现 IList 接口的类的链接,或者提供至少实现 AddRemove<的代码/code> 方法?

Can you please provide me some link to a class that implements IList<T> interface or provide me a code that at least implements Add and Remove methods?

推荐答案

除非您有非常令人信服的理由这样做,否则最好的办法是从 System.Collections.ObjectModel.Collection 因为它有你需要的一切.

Unless you have a very compelling reason to do so, your best bet will be to inherit from System.Collections.ObjectModel.Collection<T> since it has everything you need.

请注意,虽然 IList 的实现者不需要将 this[int](索引器)实现为 O(1)(基本上,常量-时间访问),强烈建议您这样做.

Please note that although implementors of IList<T> are not required to implement this[int] (indexer) to be O(1) (basically, constant-time access), it's strongly recommended you do so.

这篇关于实现 IList 接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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