IList<int> list = new List<int>();
List<int> list = new List<int>();
这两个有没有区别?

解决方案 »

  1.   

    namespace System.Web.UI.MobileControls
    {
        // Summary:
        //     Renders a list of items as either a static display or an interactive list.
        [ToolboxItem("System.Web.UI.Design.WebControlToolboxItem, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
        [ToolboxData(@"<{0}:List runat=""server""></{0}:List>")]
        [DefaultEvent("ItemCommand")]
        [DefaultProperty("DataSource")]
        [ControlBuilder(typeof(ListControlBuilder))]
        public class List : PagedControl, INamingContainer, ITemplateable, IPostBackEventHandler
    using System;
    using System.Reflection;
    using System.Runtime.InteropServices;namespace System.Collections
    {
        // Summary:
        //     Represents a non-generic collection of objects that can be individually accessed
        //     by index.
        [ComVisible(true)]
        public interface IList : ICollection, IEnumerable
    继承的东西不一样
      

  2.   

    使用接口而非具体类型,是OOP中比较普遍的原则,其核心价值在于解除对特定类的依赖,通过接口将对象的行为与具体实现隔离开来.
    接口实现松耦合,有利于系统的维护与重构.
      

  3.   

    1、当你只想使用接口的方法时,这种方式比较好.他不获取实现这个接口的类的其他方法和字段,有效的节省空间.2、IList <>是个接口,定义了一些操作方法这些方法要你自己去实现
    List <>是个类型 已经实现了IList <>定义的那些方法IList <Class1> IList11 =new List <Class1>();
    List <Class1> List11 =new List <Class1>();这两行代码,从操作上来看,实际上都是创建了一个List<Class1>对象的实例,也就是说,他们的操作没有区别。只是用于保存这个操作的返回值变量类型不一样而已。那么,我们可以这么理解,这两行代码的目的不一样。
    List <Class1> List11 =new List <Class1>();
    是想创建一个List<Class1>,而且需要使用到List<T>的功能,进行相关操作。

    IList <Class1> IList11 =new List <Class1>();
    只是想创建一个基于接口IList<Class1>的对象的实例,只是这个接口是由List<T>实现的。所以它只是希望使用到IList<T>接口规定的功能而已。
      

  4.   

    有区别,List还实现了很多其他的东西,
    如果不需要的话,就用IList.