List (of T) 和 Collection(of T) 有什么区别? [英] What is the difference between List (of T) and Collection(of T)?

查看:44
本文介绍了List (of T) 和 Collection(of T) 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到它们以很多相同的方式使用,我担心如果我不能更好地理解这一点,我将在设计中走上一条不可逆转的道路.另外,我正在使用 .NET.

I've seen them used in a lot of the same ways, and I am worried I'm about to go down a path in design that is irreversible if I don't understand this better. Also, I am using .NET.

推荐答案

Collection 是一个围绕 IList 的可定制包装器.虽然 IList 不是密封的,但它不提供任何自定义点.Collection 的方法默认委托给标准的 IList 方法,但可以很容易地覆盖以执行您想要的操作.还可以在 Collection 中连接事件,我认为 IList 无法完成这些事件.

Collection<T> is a customizable wrapper around IList<T>. While IList<T> is not sealed, it doesn't provide any customization points. Collection<T>'s methods are by default delegated to the standard IList<T> methods, but can be easily overridden to do what you want. It is also possible to wireup events inside a Collection<T> that I don't believe could be done with an IList.

简而言之,事后扩展它要容易得多,这可能意味着更少的重构.

In short, it's much easier to extend it after the fact, which could potentially mean a lot less refactoring.

这篇关于List (of T) 和 Collection(of T) 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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