清单< T>或IList的< T> [英] List<T> or IList<T>

查看:153
本文介绍了清单< T>或IList的< T>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能给我解释一下我为什么会想在C#中使用的IList超过列表?

Can anyone explain to me why I would want to use IList over List in C#?

相关问题:为什么认为是坏,露出列表< T>

推荐答案

如果您通过其他人会使用一个库暴露你的类,你通常要通过接口而不是具体实现揭露它。如果您决定以后更改类的实现使用不同的具体类这将帮助。在这种情况下,磁带库的用户并不需要更新其code,因为接口不改变。

If you are exposing your class through a library that others will use, you generally want to expose it via interfaces rather than concrete implementations. This will help if you decide to change the implementation of your class later to use a different concrete class. In that case the users of your library won't need to update their code since the interface doesn't change.

如果你只是使用它的内部,你可能顾不了那么多,并使用列表< T> 可确定

If you are just using it internally, you may not care so much, and using List<T> may be ok.

这篇关于清单&LT; T&GT;或IList的&LT; T&GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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