Loading [MathJax]/jax/output/CommonHTML/config.js
前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >最全数据结构详述: List VS IEnumerable VS IQueryable VS ICollection VS IDictionary

最全数据结构详述: List VS IEnumerable VS IQueryable VS ICollection VS IDictionary

作者头像
葡萄城控件
发布于 2018-01-10 05:14:03
发布于 2018-01-10 05:14:03
2K00
代码可运行
举报
运行总次数:0
代码可运行

本文对常用的数据结构详述:Array, ArrayList,List,IList,ICollection, Stack, Queue, HashTable, Dictionary, IQueryable, IEnumerable。

Collection(集合)

Collection是数据记录集合,

编写代码过程中,常常需要合适的容器保存临时数据,方便修改和查找,如何选取合适的数据容器,关键在于将执行的数据操作以及数据记录是否大量。

Array(数组)

特征

1. 固定大小,数组的大小是初始化时决定无法修改的数值。

2. 强类型,存储数据元素类型必须在初始化时指定,因此在运行时,不需要耗费额外的时间来定义数组类型,能够大大提升运行效率。

3. 可使用Foreach关键字实现数组迭代和查找。

因为数组大小是固定的,且是强类型数据结构,因此在运行时只占用很少的内存,运行时效率很高。

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
       //It is obvious that strArray is
       //1. string   --> Strongly Type
       //2. Sized=10 --> Fixed Size
     
        string[] strArray = new string[10];
     
           for (int i = 0; i < 10; i++)
           {
            if (strArray[i]==null)
              {
                  strArray[i] = (i+1).ToString();
              }
          }
     
          this.ListBoxArray.DataSource = null;
          this.ListBoxArray.Items.Clear();
     
          this.ListBoxArray.DataSource = strArray;
          this.ListBoxArray.DataBind();

ArrayList

1. ArrayList 没有固定的长度,容量可动态增加,可应用于开发人员无法确定数组元素个数等场景,当然这种情况下,在定义结构体的时候会非常耗时。

2. ArrayList 不是强类型,ArrayList中不同元素类型可以不相同,并且需要在运行时根据实际的输入来确定元素类型。因此在运行时消耗内存较多。

3. 可使用Froeach 关键字操作ArrayList。

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
public class Product
         {
             public Product()
             {
             
             }
             public Product(string Code, string Name)
             {
                 _Code = Code;
                 _Name = Name;
             }
     
                public string _Code {get; set;}
                public string _Name { get; set; }
        }

ArrayList支持String,int,以及十进制小数类型。

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
   //It is NOT obvious that strArrayList is 1. string? int? object? decimal?  --> NOT Strongly Type
   //                                       2. Sized=10? 20? 100?             -->NOT Fixed Size
   // Namespace: System.Collections
      
   System.Collections.ArrayList strArrayList = new System.Collections.ArrayList();
   //System.Linq.IQueryable  type of data is not specific runtime defered support
   strArrayList.Add("Mahsa");  //   "Mahsa": is string
   strArrayList.Add(1);        //        1 : is integer
   strArrayList.Add(0.89);     //      0.89: is decimal
     
     this.ListBoxArrayList.DataSource = null;
     this.ListBoxArrayList.Items.Clear();
     this.ListBoxArrayList.DataSource = strArrayList;
     this.ListBoxArrayList.DataBind();
     
     System.Text.StringBuilder str= new System.Text.StringBuilder();
     
     foreach (var item in strArrayList)
     {
         str.Append(" , "+item);
     }
     this.lblArrayList.Text = str.ToString();
     
     //Below is old way to fill obj from product , in Arraylist you need to create more than one instance
    // Product objProduct = new Product();
    // objProduct.Code = "1001";
    // objProduct.Name = "Chair";
     
     //It is NOT obvious that strArrayList is
     //1. string? int? object? decimal? OR OBJECT??  --> NOT Strongly Type   //2. Sized=10? 20? 100?                         -->NOT Fixed Size
     // Namespace: System.Collections   
     System.Collections.ArrayList objArrayList = new System.Collections.ArrayList();
     
     objArrayList.Add(new Product("1001", "Chair"));
     objArrayList.Add(new Product("1002", "Sofa"));
     objArrayList.Add(new Product("1003", "Carpet"));
     
     this.DropDownListArrayListObject.DataSource = null;
     this.DropDownListArrayListObject.Items.Clear();
     this.DropDownListArrayListObject.DataSource = objArrayList;
     
     //* Finding among Object of Array List is difficult , you have to find your specific item by index
     Product objTemp = (Product)objArrayList[0];
     objArrayList.Remove(objTemp);
     //*
     this.DropDownListArrayListObject.DataTextField = "_Name";
     this.DropDownListArrayListObject.DataValueField = "_Code";
     this.DropDownListArrayListObject.DataBind();
     this.GridViewArrayListObject.DataSource = objArrayList;
     this.GridViewArrayListObject.DataBind();

HashTable(哈希表)

HashTable是一种定义关键字的数据结构体,使用哈希表查找数据非常方便,哈希表既不是强类型也不固定大小限制。

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
            //It is NOT obvious that strArrayList is
           //1. string? int? object? decimal? OR OBJECT??  --> NOT Strongly Type
           //2. Sized=10? 20? 100?                         -->NOT Fixed Size
           // Namespace: System.Collections
           //Hashtable solve the problem in Arraylist when we are looking for specific item
           //Hashtable dedicate a key for each item, then finding item is easier and faster
     
            System.Collections.Hashtable objHashTable = new System.Collections.Hashtable();
     
            objHashTable.Add("1001","Chair");
            objHashTable.Add("1002", "Sofa");
            objHashTable.Add("1003", "Carpet");   
     
           this.DropDownListHashTable.DataSource = null;
           this.DropDownListHashTable.Items.Clear();
           this.DropDownListHashTable.DataSource = objHashTable;
           //* finding item is easier you just need to point to it by call its key
           objHashTable.Remove("1002");
           //*
           this.DropDownListHashTable.DataTextField = "Value";
           this.DropDownListHashTable.DataValueField = "Key";
           this.DropDownListHashTable.DataBind();

Stack

栈是最典型的数据结构,栈具有优先级划分的数据结构,栈为每个内容项定义优先级,表示每个Item入栈和出栈的优先顺序。因此操作栈中的数据,需要先将数据push 到栈的顶部,需要删除元素必须变成栈顶部,即要遵守后进先出(LIFO)的原则。

栈与哈希表一样既不是强类型也不限制元素个数。

Push 操作

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
            //Stack is LIFO: Last in First Out
            System.Collections.Stack objStackPush = new System.Collections.Stack();
     
            //By Push method you can insert item at the top of the stack
            objStackPush.Push("Mahsa");
            objStackPush.Push("Hassankashi");
            this.lblPop.Text = "";
            this.ListBoxStack.DataSource = objStackPush.ToArray();
            this.ListBoxStack.DataBind();

Pop操作

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
    System.Collections.Stack objStackPop = new System.Collections.Stack();
    
    objStackPop.Push("Mahsa");
    objStackPop.Push("Hassankashi");  
     
    //By Pop method you can remove item from the top of the stack --> Last in First in
    this.lblPop.Text = objStackPop.Pop().ToString();
      
    this.ListBoxStack.DataSource = objStackPop.ToArray();
    this.ListBoxStack.DataBind();

Queue

Queue同栈一样也是具有优先级定义的结构体,遵循的规则是先进先出(FIFO),既不是强类型也不具有固定的大小限制。

入队操作

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
      //Queue is FIFO: First in First Out
     System.Collections.Queue objQueue = new System.Collections.Queue();
      
     //By Enqueue method you can insert item at the END of the Queue
     objQueue.Enqueue("Mahsa");
     objQueue.Enqueue("Hassankashi");
     objQueue.Enqueue("Cosmic");
     objQueue.Enqueue("Verse");
     
     this.lblQueue.Text = "";
     this.ListBoxQueue.DataSource = objQueue.ToArray();
     this.ListBoxQueue.DataBind();

出队操作

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
   1:  System.Collections.Queue objQueue = new System.Collections.Queue();
   2:   
   3:  objQueue.Enqueue("Mahsa");
   4:  objQueue.Enqueue("Hassankashi");
   5:  objQueue.Enqueue("Cosmic");
   6:  objQueue.Enqueue("Verse");
   7:   
   8:  //By Dequeue method you can remove item from the BEGINING of the Queue --> First in First out FIFO
   9:  this.lblQueue.Text=objQueue.Dequeue().ToString();
  10:   
  11:  this.ListBoxQueue.DataSource = objQueue.ToArray();
  12:  this.ListBoxQueue.DataBind();

入队操作

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
   1:  System.Collections.Queue objQueue = new System.Collections.Queue();
   2:   
   3:  objQueue.Enqueue("Mahsa");
   4:  objQueue.Enqueue("Hassankashi");
   5:  objQueue.Enqueue("Cosmic");
   6:  objQueue.Enqueue("Verse");
   7:   
   8:  //By Dequeue method you can remove item from the BEGINING of the Queue --> First in First out FIFO
   9:  this.lblQueue.Text=objQueue.Dequeue().ToString();
  10:   
  11:  this.ListBoxQueue.DataSource = objQueue.ToArray();
  12:  this.ListBoxQueue.DataBind();

什么情况下需要使用List?

1. List长度可不固定

2. 当数据为通用类型,List是强类型,List中元素类型不需要等到运行时来确定,这种特性使得List 运行时效率非常高。

3. 可使用Foreach关键字。

因为List不需要设定固定的大小,List灵活度高,且效率高常用于开发过程中。

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
   1:  //Like Array is Strong Type
   2:  //Like ArrayList with No Dimension
   3:  System.Collections.Generic.List<string> strList = new List<string>();
   4:   
   5:   
   6:  strList.Add("Mahsa");
   7:  strList.Add("Hassankashi");
   8:  strList.Add("Cosmic");
   9:  strList.Add("Verse");
  10:   
  11:  this.ListBoxListGeneric.DataSource = strList;
  12:  this.ListBoxListGeneric.DataBind();
  13:   
  14:  System.Text.StringBuilder str = new System.Text.StringBuilder();
  15:   
  16:  foreach (var item in strList)
  17:  {
  18:      str.Append(" , " + item);
  19:  }
  20:  this.lblList.Text = str.ToString();

IList

IList 继承了List,包含多种方法的List接口。如果你无法判断代码改动的可能性,可以使用IList接口,减少模块之间的依赖性。IList是接口因此无法被实例化,所以必须使用List来初始化。

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
   1:  System.Collections.Generic.IList<string> strIList = new List<string>();

我们一起了解一下具体的类和接口之间的区别。

1. 具体类可继承其他类,并实现一个或多个接口。

2. 在内部类中可以定义变量并赋值,接口中不允许此操作。

3. 具体类可包含构造函数,而接口中不能定义构造函数

4. 抽象类中可包含访问修饰符如public,private等,接口中不能包含。

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
   1:  //Ilist can not be instantiate from Ilist , so it should be instantiate from List
   2:  System.Collections.Generic.IList<string> strIList = new List<string>();
   3:   
   4:  strIList.Add("Mahsa");
   5:  strIList.Add("Hassankashi");
   6:  strIList.Add("Cosmic");
   7:  strIList.Add("Verse");
   8:   
   9:   
  10:  this.ListBoxListGeneric.DataSource = strIList;
  11:  this.ListBoxListGeneric.DataBind();
  12:   
  13:  System.Text.StringBuilder str = new System.Text.StringBuilder();
  14:   
  15:  foreach (var item in strIList)
  16:  {
  17:      str.Append(" , " + item);
  18:  }
  19:  this.lblList.Text = str.ToString();

IEnumerable

IEnumerable常用于遍历集合元素,但是无法修改(删除或添加)数据,使用IEnumberable 会从服务器端将所有数据拷贝到客户端,并进行一定的过滤,如果服务器端有大量数据会造成内存负载超重。

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
   1:  //IEnumerable can not be instantiate from Enumerable , so it should be instantiate from List
   2:         System.Collections.Generic.IEnumerable<Employee> empIEnumerable = new List<Employee>
   3:         {   new Employee { ID = 1001, Name="Mahsa"},
   4:             new Employee { ID = 1002, Name = "Hassankashi" },
   5:             new Employee { ID = 1003, Name = "CosmicVerse" },
   6:             new Employee { ID = 1004, Name = "Technical" }
   7:         };
   8:   
   9:   
  10:         this.GridViewIEnumerable.DataSource = empIEnumerable;
  11:         this.GridViewIEnumerable.DataBind();
  12:   
  13:         System.Text.StringBuilder str = new System.Text.StringBuilder();
  14:   
  15:         foreach (Employee item in empIEnumerable)
  16:         {
  17:             str.Append(" , " + item.ID +"-"+item.Name);
  18:         }
  19:   
  20:         this.lblIEnumerable.Text = str.ToString();
IQueryable
IQueryable与IEnumberable不同的是,当从服务器端加载过量的数据,IQueryable会自动减少应用负载。IQueryable可保证大数据量时应用程序的高性能。
IQueryable会先过滤数据,然后发送给客户端。
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
   1:  DataAccessEntities ctx = new DataAccessEntities();
   2:          var ctx = new DataAccessEntities();
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
   1:  //Difference between IQueryable and IEnumerable
   2:   
   3:          //You can instantiate IEnumerable from List
   4:   
   5:          IEnumerable<employee> queryIEnumerable = new List<employee>() ;
   6:   
   7:   
   8:          //Bring  ALL records from server --> to client then filter collection
   9:         //To bring all data from server you should omit where cluse from linq to sql 
   10:          queryIEnumerable = from m in ctx.Employees select m;
   11:   
   12:          //If you use where as extension method with IEnumerable then All records will be loaded 
   13:          queryIEnumerable = queryIEnumerable.Where(x => x.ID == 1).ToList();
   14:        
   15: 
   16:   
   17:          //You can not instantiate IQueryable
   18:   
   19:          IQueryable<employee> queryIQueryable=null;
   20:  
   21:          //Bring just ONE record from server --> to client
   22:   
   23:          queryIQueryable = (from m in ctx.Employees
   24:                       where m.ID == 1
   25:                       select m);
   26:   
   27:          //Whenever you call IQueryable so ==> It will be executed 
   28:          this.GridViewIQueryable.DataSource = queryIQueryable.ToList();
   29:          this.GridViewIQueryable.DataBind();
   30:  </employee>

SQL Profiler:

如何追踪查询语句生成TSQL,生成需要的数据结构体:

Step 1:

Start -> MS SQL Server 2008 -> Performance Tools -> SQL Server Profiler

Step 2:

SQL Server Profiler -> File -> New Trace

Step 3:

输入连接数据库的用户名和密码

Step 4:

General (Tab) -> Use the Template: Standard

Step 5:

Event Selection (Tab) -> Event : TSQL -> Select : SQL-BatchCompleted | Select Show all Columns

Press Column Filter -> Database Name: Like: "DataAccess"

运行

Step 6:

查看结果

Step 7:
生成 IEnumerable数据 :
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
   1:  SELECT 
   2:  [Extent1].[ID] AS [ID], 
   3:  [Extent1].[Name] AS [Name], 
   4:  [Extent1].[Age] AS [Age]
   5:  FROM [dbo].[Employee] AS [Extent1]
生成 IQueryable :
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
SELECT 
[Extent1].[ID] AS [ID], 
[Extent1].[Name] AS [Name], 
[Extent1].[Age] AS [Age]
FROM [dbo].[Employee] AS [Extent1]
WHERE 1 = [Extent1].[ID]
ICollection 继承了IEnumberable,但是IEnumberable是基于索引的,ICollection不基于索引。
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
   1:  //IList {indexer and Modify} vs ICollection {randomly and Modify}
   2:   //Collection can not be instantiate from ICollection , so it should be instantiate from List
   3:   System.Collections.Generic.ICollection<string> strICollection = new List<string>();
   4:   strICollection.Add("Mahsa");
   5:   strICollection.Add("Hassankashi");
   6:   
   7:   //Countable***
   8:   int ICollectionCount=strICollection.Count;
   9:   
  10:   this.ListBoxICollection.DataSource = strICollection;
  11:   this.ListBoxICollection.DataBind();
  12:   System.Text.StringBuilder str = new System.Text.StringBuilder();
  13:   foreach (var item in strICollection)
  14:   {
  15:       str.Append(" , " + item);
  16:   }
  17:   this.lblICollection.Text = str.ToString();
  18:   
  19:   //IList***
  20:   System.Collections.Generic.IList<Employee> objIList = new List<Employee>();
  21:   objIList = (from m in ctx.Employees
  22:               select m).ToList();
  23:   
  24:  Employee obj = objIList.Where(i => i.Name == "Sara").FirstOrDefault();
  25:  int indexofSara= objIList.IndexOf(obj);
  26:  int cIList = objIList.Count;
  27:   
  28:   //ICollection***
  29:   System.Collections.Generic.ICollection<Employee> objICollection = new List<Employee>();
  30:   objICollection = (from m in ctx.Employees
  31:                     select m).ToList();
  32:   Employee objIC = objICollection.Where(i => i.Name == "Sara").FirstOrDefault();
  33:   //You can not get index of object , if you clear comment from below code appears error
  34:  // int indexofSaraICollection = objIC.IndexOf(objIC);
  35:   int cICollection = objICollection.Count;

入栈:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
   1:  //Stack is LIFO: Last in First Out
   2:         //Here is for Push Stack in Generic
   3:         //System.Collections.Stack objStackPush = new System.Collections.Stack();
   4:         //Stack<T> can be instantiated from Stack<T>
   5:   
   6:         System.Collections.Generic.Stack<int> objStackPush = new System.Collections.Generic.Stack<int>();
   7:   
   8:         objStackPush.Push(1);
   9:         objStackPush.Push(2);
  10:   
  11:         this.lblPopGeneric.Text = "";
  12:         this.ListBoxStackGeneric.DataSource = objStackPush.ToArray();
  13:         this.ListBoxStackGeneric.DataBind();

出栈:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
   1:  //Stack is LIFO: Last in First Out
   2:         //Here is for Pop Stack in Generic
   3:         //System.Collections.Stack objStackPop = new System.Collections.Stack();
   4:         //Stack<T> can be instantiated from Stack<T>
   5:   
   6:         System.Collections.Generic.Stack<int> objStackPop = new System.Collections.Generic.Stack<int>();
   7:   
   8:         objStackPop.Push(1);
   9:         objStackPop.Push(2);
  10:   
  11:         this.lblPop.Text = objStackPop.Pop().ToString();
  12:         this.ListBoxStack.DataSource = objStackPop.ToArray();
  13:         this.ListBoxStack.DataBind();

Queue Generic

入队:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
   1:  //Queue is FIFO: First in First Out
   2:         //Here is for Enqueue Queue in Generic
   3:         //System.Collections.Queue objQueue = new System.Collections.Queue();
   4:         //Queue<T> can be instantiated from Queue<T>
   5:   
   6:         System.Collections.Generic.Queue<int> objQueue = new System.Collections.Generic.Queue<int>();
   7:         objQueue.Enqueue(1);
   8:         objQueue.Enqueue(2);
   9:   
  10:         this.lblQueue.Text = "";
  11:   
  12:         this.ListBoxQueue.DataSource = objQueue.ToArray();
  13:         this.ListBoxQueue.DataBind();

出队:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
   1:  //Queue is FIFO: First in First Out
   2:         //Here is for Enqueue Queue in Generic
   3:         //System.Collections.Queue objQueue = new System.Collections.Queue();
   4:         //Queue<T> can be instantiated from Queue<T>
   5:   
   6:         System.Collections.Generic.Queue<int> objQueue = new System.Collections.Generic.Queue<int>();
   7:         objQueue.Enqueue(1);
   8:         objQueue.Enqueue(2);
   9:   
  10:         this.lblQueue.Text = "";
  11:   
  12:         this.ListBoxQueue.DataSource = objQueue.ToArray();
  13:         this.ListBoxQueue.DataBind();
Dictionary 及 IDictionary:
Dictionary 可通用,而哈希表不是通用的。Dictionary定义 <TKey,Tvalue>。IDictionary是Dictionary的接口,如果在后期开发中需要大量修改,建议使用IDictionary。
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
//Dictionary can instantiate from Dictionary , Dictionary is similar to Hashtable,
//Dictionary is GENERIC but Hashtable is NON GENERIC
//Such Hashtable you can find object by its key
System.Collections.Generic.Dictionary<int, string=""> objDictionary = new Dictionary<int, string="">();

objDictionary.Add(1001, "Mahsa");
objDictionary.Add(1002, "Hassankashi");
objDictionary.Add(1003, "Cosmicverse");

string str = objDictionary[1002];

this.ListBoxDictionary.DataSource = objDictionary;
this.ListBoxDictionary.DataBind();</int,>
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2015-11-06 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
.NET面试题系列[10] - IEnumerable的派生类
IEnumerable分为两个版本:泛型的和非泛型的。IEnumerable只有一个方法GetEnumerator。如果你只需要数据而不打算修改它,不打算为集合插入或删除任何成员(例如从远端拿回数据显示),则你不需要任何比IEnumerable更复杂的接口。
s055523
2018/09/14
8610
.NET面试题系列[10] - IEnumerable的派生类
.NET面试题系列[11] - IEnumerable<T>的派生类
ICollection<T>继承IEnumerable<T>。在其基础上,增加了Add,Remove等方法,可以修改集合的内容。IEnumerable<T>的直接继承者还有Stack<T>和Queue<T>。
s055523
2018/09/14
1.9K0
.NET面试题系列[11] - IEnumerable<T>的派生类
C# 队列(Queue)
//Queue队列就是先进先出。它并没有实现 IList,ICollection。所以它不能按索引访问元素,不能使用Add和Remove。下面是 Queue的一些方法和属性
zls365
2020/08/19
6720
C#语言各种集合介绍
集合,表示可以通过遍历每个元素来访问的一组对象(特别是可使用foreach循环访问) 一个集合包括多个元素,即有一个集合类对象和N个元素对象
全栈程序员站长
2022/07/15
6650
C#基础与常用数据结构学习笔记
  接口相当于没有方法实现的抽象类,接口方法不要加各种访问级别:例如public,private等。
Edison Zhou
2018/08/20
4930
C# 基础知识系列- 3 集合数组
C#/.NET Framework 提供了很多很有意思的集合类,数组、列表、链表、Set、字典等一系列的类。其中数组是语言的一部分,个人认为严格意义上不属于集合类这一部分。C#开发中常用的集合有数组、 List类、Set接口、Dictionary类、Queue类、LinkedList类等,其他的出镜率不高。与其他(java)语言不同的一点是,C#的List是类,而不是接口,接口是IList,但这个接口意义不大,在使用IList的时候更多的倾向于使用IEnumerable,这主要是因为IEnumerable 有 Linq的支持再者两者的方法基本一致,能用IList的地方基本都可以用IEnumerable。
程序员小高
2020/04/29
1.4K0
C# 静态与动态数组
C#中的数组是由System.Array类衍生出来的引用对象,因此可以使用Array类中的各种方法对数组进行各种操作。
王瑞MVP
2022/12/28
1.7K0
发布一款层次下拉列表控件
在项目中经常遇到树状结构的对象比如产品分类、部门结构、地区……对于这类对象的呈现,一般都使用树控件(比如VS2005自带的TreeView控件)。但是树控件的使用和操作都比较复杂,对于一些比较简单的操作,比如单选其中的一个节点的情况则可用使用下拉列表框来代替。要在DropDownList中展示出树结构的层次,那就必须在每个节点的Text前加入一定的占位符,以实现层次的效果,比如:
深蓝studyzy
2022/06/16
5250
CA1010:集合应实现泛型接口
类型实现 System.Collections.IEnumerable 接口,但不能实现 System.Collections.Generic.IEnumerable<T> 接口和包含程序集的目标 .NET。 此规则会忽略能够实现 System.Collections.IDictionary 的类型。
用户4268038
2022/01/10
6460
数据结构与算法2016-06-03
一个算法调用自己来完成它的部分工作,在解决某些问题时,一个算法需要调用自身。如果一个算法直接调用自己或间接调用自己,就称这个算法是递归的。根据调用方式的不同,它分为直接递归和间接递归。
2018/09/03
3270
编写高质量代码改善C#程序的157个建议[勿选List<T>做基类、迭代器是只读的、慎用集合可写属性]
  本文已更新至http://www.cnblogs.com/aehyok/p/3624579.html 。本文主要学习记录以下内容:
aehyok
2018/08/31
6020
编写高质量代码改善C#程序的157个建议[勿选List<T>做基类、迭代器是只读的、慎用集合可写属性]
# C#学习-泛型-集合-堆栈-队列-哈希-字典
C#中的泛型能够将类型作为参数来传递,即在创建类型时用一个特定的符号如T来作为一个占位符,代替实际的类型,等待在实例化时再用一个实际的类型来代替:
呆呆敲代码的小Y
2022/05/07
9830
# C#学习-泛型-集合-堆栈-队列-哈希-字典
C#基础深入学习02
Hashtable 类代表了一系列基于键的哈希代码组织起来的键/值对。它使用键来访问集合中的元素。
Echo_Wish
2023/11/30
2120
C#基础知识系列十(集合)
  本节主要是来了解学习集合,以方便在程序编写时,什么地方该选用什么集合,让程序更健壮的运行起来。在学习了解集合之前,首先需要了解一些数据结构方面的知识。下面我们就先简单的来看一下数据结构。
aehyok
2018/08/31
7160
C#基础知识系列十(集合)
C#集合类型大揭秘
集合是.NET FCL(Framework Class Library)的重要组成部分,我们平常撸C#代码时免不了和集合打交道,FCL提供了丰富易用的集合类型,给我们撸码提供了极大的便利。正是因为这种
撸码那些事
2018/06/21
1.6K0
C#操作json的通用帮助类
using System; using System.Data; using System.Text; using System.Collections.Generic; using System.Reflection; using System.Data.Common; using System.Collections; using System.IO; using System.Text.RegularExpressions; using System.Runtime.Serialization.Jso
用户7108768
2021/11/02
1.4K0
C#规范整理·集合和Linq
LINQ(Language Integrated Query,语言集成查询)提供了类似于SQL的语法,能对集合进行遍历、筛选和投影。一旦掌握了LINQ,你就会发现在开发中再也离不开它。
郑子铭
2023/08/30
4260
C#规范整理·集合和Linq
快速入门系列--CLR--03泛型集合
.NET中的泛型集合 在这里主要介绍常见的泛型集合,很多时候其并发时的线程安全性常常令我们担忧。因而简述下.NET并发时线程安全特性,其详情请见MSDN。 普通集合都不支持多重并发写操作 部分支持单线程写和并发读操作 同时.NET4添加了大量并发集合 首先介绍常见的泛型集合接口,其大部分都位于System.Collection.Generic命名空间。 IEnumerable<T>,其可以获取一个IEnumerator<T>迭代器,如果从数据库的角度来看,前者是表,后者是游标
用户1216676
2018/01/24
8010
.net源码分析 – List<T>
通过分析源码可以更好理解List<T>的工作方式,帮助我们写出更稳定的代码。 List<T>源码地址: https://github.com/dotnet/corefx/blob/master/sr
用户1147588
2018/01/04
7530
.net源码分析 – List<T>
C#透彻解析数组、ArrayList和List的区别
在C#中数组,ArrayListList都能够存储一组对象,那么这三者到底有什么样的区别呢。
用户9127601
2021/11/01
1.4K0
相关推荐
.NET面试题系列[10] - IEnumerable的派生类
更多 >
LV.2
这个人很懒,什么都没有留下~
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
本文部分代码块支持一键运行,欢迎体验
本文部分代码块支持一键运行,欢迎体验