常用接口简析3---IList和List的解析

时间:2024-04-30 12:49:12

常用接口的解析(链接)

1.IEnumerable深入解析
2.IEnumerable、IEnumerator接口解析
3.IComparable、IComparable接口解析

学习第一步,先上菜:

 #region 程序集 mscorlib.dll, v4.0.30319
// C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\mscorlib.dll
#endregion using System;
using System.Collections;
using System.Reflection;
using System.Runtime.CompilerServices; namespace System.Collections.Generic
{
// 摘要:
// 表示可按照索引单独访问的一组对象。
//
// 类型参数:
// T:
// 列表中元素的类型。
[TypeDependency("System.SZArrayHelper")]
public interface IList<T> : ICollection<T>, IEnumerable<T>, IEnumerable
{
// 摘要:
// 获取或设置指定索引处的元素。
//
// 参数:
// index:
// 要获得或设置的元素从零开始的索引。
//
// 返回结果:
// 指定索引处的元素。
//
// 异常:
// System.ArgumentOutOfRangeException:
// index 不是 System.Collections.Generic.IList<T> 中的有效索引。
//
// System.NotSupportedException:
// 设置该属性,而且 System.Collections.Generic.IList<T> 为只读。
T this[int index] { get; set; } // 摘要:
// 确定 System.Collections.Generic.IList<T> 中特定项的索引。
//
// 参数:
// item:
// 要在 System.Collections.Generic.IList<T> 中定位的对象。
//
// 返回结果:
// 如果在列表中找到,则为 item 的索引;否则为 -1。
int IndexOf(T item);
//
// 摘要:
// 将一个项插入指定索引处的 System.Collections.Generic.IList<T>。
//
// 参数:
// index:
// 从零开始的索引,应在该位置插入 item。
//
// item:
// 要插入到 System.Collections.Generic.IList<T> 中的对象。
//
// 异常:
// System.ArgumentOutOfRangeException:
// index 不是 System.Collections.Generic.IList<T> 中的有效索引。
//
// System.NotSupportedException:
// System.Collections.Generic.IList<T> 为只读。
void Insert(int index, T item);
//
// 摘要:
// 移除指定索引处的 System.Collections.Generic.IList<T> 项。
//
// 参数:
// index:
// 从零开始的索引(属于要移除的项)。
//
// 异常:
// System.ArgumentOutOfRangeException:
// index 不是 System.Collections.Generic.IList<T> 中的有效索引。
//
// System.NotSupportedException:
// System.Collections.Generic.IList<T> 为只读。
void RemoveAt(int index);
}
}

List的内容太多了

 public class List<T> : IList<T>, ICollection<T>, IEnumerable<T>, IList, ICollection, IEnumerable

从上面内容就可以看到,List继承了三个泛型接口,还继承了三个常规的接口。

说白了,就是List是类,继承IList<T>泛型版本和IList非泛型版本接口。List是一个集合类。

IList<T>是接口,说明这个对象要去实现接口里定义的方法。

IList<T> 服务泛型集合(List<T>),IList服务非泛型集合(Array)

以上只是个人学习的理解,后续会进行跟进,大家有什么想法可以畅所欲言。