您能告诉我ilist和list之间的区别吗,在项目中的何处使用 [英] can u tell me the difference between ilist and list ,where to use in the project

查看:134
本文介绍了您能告诉我ilist和list之间的区别吗,在项目中的何处使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您能告诉我ilist和list之间的区别吗,在项目中的使用位置

can u tell me the difference between ilist and list ,where to use in the project

推荐答案

在提出问题之前,请阅读以下讨论:
如何问一个好问题? [ google [列表< t>类 [ ^ ]
IList界面 [ CodeProject [ ^ ]类似的答案.
Before asking questions, please read this discussion:
How to ask a good question?[^]

Try simple search on google[^] with your question, you''ll get About 95,800 results (0.20 seconds).

You can also try on MSDN:
List<t> Class[^]
IList Interface[^]

Moreover you can try CodeProject[^] similar answers.



列表< &是IList< T>是一个容器,可以使用整数索引以与线性数组T []相同的方式进行寻址.当将IList指定为方法的参数类型时,仅指定需要容器的某些功能.

例如,接口规范没有强制使用特定的数据结构. List< &对于线性数组,在访问,删除和添加元素时的性能相同.但是,您可以想象有一个由链表支持的实现,在该实现的末尾添加元素更便宜(恒定时间),而随机访问则要昂贵得多. (请注意,.NET LinkedList< T>并未实现IList< T>.)
本示例还告诉您,在某些情况下,您需要在参数列表中指定实现而不是接口:在本示例中,每当您需要特定的访问性能特征时.通常对于容器的特定实现可以保证这一点(List< T>文档:它使用其大小根据需要动态增加的数组来实现IList< T>通用接口".)

此外,您可能需要考虑公开所需的最少功能.例如.如果您不需要更改列表的内容,则应该考虑使用IEnumerable< T> ;,其中IList< &扩展.
Hi ,
List< T > is a specific implementation of IList< T >, which is a container that can be addressed the same way as a linear array T[] using an integer index. When you specify IList as the type of the method''s argument, you only specify that you need certain capabilities of the container.

For example, the interface specification does not enforce a specific data structure to be used. The implementation of List< T > happens to the same performance for accessing, deleting and adding elements as a linear array. However, you could imagine an implementation that is backed by a linked list instead, for which adding elements to the end is cheaper (constant-time) but random-access much more expensive. (Note that the .NET LinkedList< T > does not implement IList< T >.)

This example also tells you that there may be situations when you need to specify the implementation, not the interface, in the argument list: In this example, whenever you require a particular access performance characteristic. This is usually guaranteed for a specific implementation of a container (List< T > documentation: "It implements the IList< T > generic interface using an array whose size is dynamically increased as required.").

Additionally, you might want to consider exposing the least functionality you need. For example. if you don''t need to change the content of the list, you should probably consider using IEnumerable< T >, which IList< T> extends.


IList仅公开接口IList
公开的方法.
IList will only expose the methods exposed by the interface IList
IList<int> myList = new List<int>(); </int></int>


List将公开List对象的所有成员


List will expose all members of the List object

List<int> myList = new List<int>(); </int></int>



如果要通过供他人使用的库公开类,则通常希望通过接口而不是具体的实现公开它.如果您以后决定更改类的实现以使用其他具体类,则这将有所帮助.在这种情况下,您的库的用户将不需要更新其代码,因为界面不会更改.
如果您仅在内部使用它,则可能不太在意,使用List<t>;</t>可能没问题.

请查看以下链接以获取更多信息:
http://forums.asp.net/t/1775855.aspx/1 [ ^ ]
http://forums.asp.net/t/1231995.aspx/1 [ ^ ]
http://oreilly.com/catalog/pnetcomp2/chapter/ch03.pdf [ ^ ]



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 will not need to update their code since the interface does not change.
If you are just using it internally, you may not care so much, and using List<t>;</t> may be ok.

Look at below links for more information:
http://forums.asp.net/t/1775855.aspx/1[^]
http://forums.asp.net/t/1231995.aspx/1[^]
http://oreilly.com/catalog/pnetcomp2/chapter/ch03.pdf[^]


这篇关于您能告诉我ilist和list之间的区别吗,在项目中的何处使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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