zoukankan      html  css  js  c++  java
  • 泛型接口的定义与使用


           IList 表示可以按照索引单独访问的对象的非泛型集合。IList 是 ICollection 接口的子代,并且是所有非泛型列表的基接口。IList 实现有三种类别:只读、固定大小和可变大小。无法修改只读 IList。固定大小的 IList 不允许添加或移除元素,但允许修改现有元素。可变大小的 IList 允许添加、移除和修改元素。

    IList(T) 泛型接口 表示可按照索引单独访问的一组对象。

     //定义泛型接口

     public interface ICategory  
    {

        IList
    <CategoryInfo> GetCategories();
        CategoryInfo GetCategory(
    string categoryId);
     } 

    //泛型接口的使用

    public IList<CategoryInfo> GetCategories()
     {
      
         IList
    <CategoryInfo> categories = new List<CategoryInfo>();
     
        
    using(SqlDataReader rdr = SqlHelper.ExecuteReader()) 
        {
                   
    while (rdr.Read()) 
                   {                    

                              CategoryInfo cat 
    = new CategoryInfo(rdr.GetString(1))                 

                               categories.Add(cat);
                    }
         }  
                
    return categories;
     }

  • 相关阅读:
    5860. 从双倍数组中还原原数组
    5847. 找到所有的农场组
    5846. 找到数组的中间位置
    442. 数组中重复的数据
    1987. 不同的好子序列数目
    1986. 完成任务的最少工作时间段
    1985. 找出数组中的第 K 大整数
    1984. 学生分数的最小差值
    学习内容整合
    spring-DI和spring-mybatis整合
  • 原文地址:https://www.cnblogs.com/zhangyg/p/1409746.html
Copyright © 2011-2022 走看看