petshop4.0中的一段代码 public interface ICategory { /// <summary>
/// Method to get all categories
/// </summary>
        /// <returns>Interface to Model Collection Generic of categories</returns>
     
       
IList<CategoryInfo> GetCategories();
               /// <summary>
        /// Get information on a specific category
        /// </summary>
        /// <param name="categoryId">Unique identifier for a category</param>
        /// <returns>Business Entity representing an category</returns>
        CategoryInfo GetCategory(string categoryId);
}
我知道IList<CategoryInfo>是范型
表示list中的item是CategoryInfo对象
请问为什么用IList<CategoryInfo>
用List<CategoryInfo>可以吗?两者有什么区别?谢谢

解决方案 »

  1.   

    楼上的说什么啊原代码就是用IList啊我问为什么用IList<CategoryInfo>
    用List<CategoryInfo>可以吗?两者有什么区别?谢谢
      

  2.   

    没有什么区别,这样写灵活性大,实现ilist接口的类很多,你写成list后,也许以后你要改成非list的,就会要改很多代码
      

  3.   

    举个例子RenderControlToString(DataList L//Control C)你认为是写control还是写datalist代码的通用性高?
      

  4.   

    OOP编码原则:尽可能用接口编程