list<T>类

在C#namespace System.Collections.Generic 这个命名空间下已经帮我们定义了一个list类,这个里面就可以实现线性表的功能,打开该命名空间可以发现其中的具体的LIST类的定义:

namespace System.Collections.Generic
{
    //
    // 摘要:
    //     表示可通过索引访问的对象的强类型列表。提供用于对列表进行搜索、排序和操作的方法。
    // 类型参数:
    public class List<T> : IList<T>, ICollection<T>, IList, ICollection, IReadOnlyList<T>, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable
    {
        //
        // 摘要:
        //     初始化 System.Collections.Generic.List`1 类的新实例,该实例为空并且具有默认初始容量。
        [TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
        public List();
        //
        // 摘要:
        //     初始化 System.Collections.Generic.List`1 类的新实例,该实例为空并且具有指定的初始容量。
        //
        // 参数:
        //   capacity:
        //     新列表最初可以存储的元素数。
        //
        // 异常:
        //   T:System.ArgumentOutOfRangeException:
        //     capacity 小于 0。
        [TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
        public List(int capacity);
        //
        // 摘要:
        //     初始化 System.Collections.Generic.List`1 类的新实例,该实例包含从指定集合复制的元素并且具有足够的容量来容纳所复制的元素。
        //
        // 参数:
        //   collection:
        //     一个集合,其元素被复制到新列表中。
        //
        // 异常:
        //   T:System.ArgumentNullException:
        //     collection 为 null。
        public List(IEnumerable<T> collection);

        //
        // 摘要:
        //     获取或设置位于指定索引处的元素。
        //
        // 参数:
        //   index:
        //     要获得或设置的元素从零开始的索引。
        //
        // 返回结果:
        //     位于指定索引处的元素。
        //
        // 异常:
        //   T:System.ArgumentOutOfRangeException:
        //     index 小于 0。- 或 -index 等于或大于 System.Collections.Generic.List`1.Count。
        public T this[int index] { get; set; }

        //
        // 摘要:
        //     获取或设置该内部数据结构在不调整大小的情况下能够容纳的元素总数。
        //
        // 返回结果:
        //     在需要调整大小之前 System.Collections.Generic.List`1 能够容纳的元素的数目。
        //
        // 异常:
        //   T:System.ArgumentOutOfRangeException:
        //     System.Collections.Generic.List`1.Capacity 设置为小于 System.Collections.Generic.List`1.Count
        //     的值。
       
        //   T:System.OutOfMemoryException:
        //     系统中没有足够的可用内存。
        public int Capacity { get; set; }
       
        // 摘要:
        //     获取 System.Collections.Generic.List`1 中包含的元素数。
        //
        // 返回结果:
        //     System.Collections.Generic.List`1 中包含的元素个数。
        public int Count { get; }

        //
        // 摘要:
        //     将对象添加到 System.Collections.Generic.List`1 的结尾处。
        //
        // 参数:
        //   item:
        //     要添加到 System.Collections.Generic.List`1 的末尾处的对象。对于引用类型,该值可以为 null。
        public void Add(T item);
        //
        // 摘要:
        //     将指定集合的元素添加到 System.Collections.Generic.List`1 的末尾。
        //
        // 参数:
        //   collection:
        //     一个集合,其元素应被添加到 System.Collections.Generic.List`1 的末尾。集合自身不能为 null,但它可以包含为 null
        //     的元素(如果类型 T 为引用类型)。
        //
        // 异常:
        //   T:System.ArgumentNullException:
        //     collection 为 null。
        public void AddRange(IEnumerable<T> collection);
        //
        // 摘要:
        //     返回当前集合的只读 System.Collections.Generic.IList`1 包装。
        //
        // 返回结果:
        //     作为当前 System.Collections.Generic.List`1 周围的只读包装的 System.Collections.ObjectModel.ReadOnlyCollection`1。
        public ReadOnlyCollection<T> AsReadOnly();
        //
        // 摘要:
        //     使用默认的比较器在整个已排序的 System.Collections.Generic.List`1 中搜索元素,并返回该元素从零开始的索引。
        //
        // 参数:
        //   item:
        //     要定位的对象。对于引用类型,该值可以为 null。
        //
        // 返回结果:
        //     如果找到 item,则为已排序的 System.Collections.Generic.List`1 中 item 的从零开始的索引;否则为一个负数,该负数是大于
        //     item 的第一个元素的索引的按位求补。如果没有更大的元素,则为 System.Collections.Generic.List`1.Count 的按位求补。
        //
        // 异常:
        //   T:System.InvalidOperationException:
        //     默认比较器 System.Collections.Generic.Comparer`1.Default 找不到 T 类型的 System.IComparable`1
        //     泛型接口或 System.IComparable 接口的实现。
        public int BinarySearch(T item);
        //
        // 摘要:
        //     使用指定的比较器在整个已排序的 System.Collections.Generic.List`1 中搜索元素,并返回该元素从零开始的索引。
        //
        // 参数:
        //   item:
        //     要定位的对象。对于引用类型,该值可以为 null。
        //
        //   comparer:
        //     比较元素时要使用的 System.Collections.Generic.IComparer`1 实现。- 或 -为 null 以使用默认比较器 System.Collections.Generic.Comparer`1.Default。
        //
        // 返回结果:
        //     如果找到 item,则为已排序的 System.Collections.Generic.List`1 中 item 的从零开始的索引;否则为一个负数,该负数是大于
        //     item 的第一个元素的索引的按位求补。如果没有更大的元素,则为 System.Collections.Generic.List`1.Count 的按位求补。
        //
        // 异常:
        //   T:System.InvalidOperationException:
        //     comparer 为 null,且默认比较器 System.Collections.Generic.Comparer`1.Default 找不到 T 类型的
        //     System.IComparable`1 泛型接口或 System.IComparable 接口的实现。
        public int BinarySearch(T item, IComparer<T> comparer);
        //
        // 摘要:
        //     使用指定的比较器在已排序 System.Collections.Generic.List`1 的某个元素范围中搜索元素,并返回该元素从零开始的索引。
        //
        // 参数:
        //   index:
        //     要搜索的范围从零开始的起始索引。
        //
        //   count:
        //     要搜索的范围的长度。
        //
        //   item:
        //     要定位的对象。对于引用类型,该值可以为 null。
        //
        //   comparer:
        //     比较元素时要使用的 System.Collections.Generic.IComparer`1 实现,或者为 null,表示使用默认比较器 System.Collections.Generic.Comparer`1.Default。
        //
        // 返回结果:
        //     如果找到 item,则为已排序的 System.Collections.Generic.List`1 中 item 的从零开始的索引;否则为一个负数,该负数是大于
        //     item 的第一个元素的索引的按位求补。如果没有更大的元素,则为 System.Collections.Generic.List`1.Count 的按位求补。
        //
        // 异常:
        //   T:System.ArgumentOutOfRangeException:
        //     index 小于 0。- 或 -count 小于 0。
        //
        //   T:System.ArgumentException:
        //     index 和 count 不表示 System.Collections.Generic.List`1 中的有效范围。
        //
        //   T:System.InvalidOperationException:
        //     comparer 为 null,且默认比较器 System.Collections.Generic.Comparer`1.Default 找不到 T 类型的
        //     System.IComparable`1 泛型接口或 System.IComparable 接口的实现。
        public int BinarySearch(int index, int count, T item, IComparer<T> comparer);
        //
        // 摘要:
        //     从 System.Collections.Generic.List`1 中移除所有元素。
        public void Clear();
        //
        // 摘要:
        //     确定某元素是否在 System.Collections.Generic.List`1 中。
        //
        // 参数:
        //   item:
        //     要在 System.Collections.Generic.List`1 中定位的对象。对于引用类型,该值可以为 null。
        //
        // 返回结果:
        //     如果在 System.Collections.Generic.List`1 中找到 item,则为 true,否则为 false。
        public bool Contains(T item);
        //
        // 摘要:
        //     将当前 System.Collections.Generic.List`1 中的元素转换为另一种类型,并返回包含转换后的元素的列表。
        //
        // 参数:
        //   converter:
        //     将每个元素从一种类型转换为另一种类型的 System.Converter`2 委托。
        //
        // 类型参数:
        //   TOutput:
        //     目标数组元素的类型。
        //
        // 返回结果:
        //     目标类型的 System.Collections.Generic.List`1,其中包含当前 System.Collections.Generic.List`1
        //     中的转换后的元素。
        //
        // 异常:
        //   T:System.ArgumentNullException:
        //     converter 为 null。
        public List<TOutput> ConvertAll<TOutput>(Converter<T, TOutput> converter);
        //
        // 摘要:
        //     将整个 System.Collections.Generic.List`1 复制到兼容的一维数组中,从目标数组的开头开始放置。
        //
        // 参数:
        //   array:
        //     作为从 System.Collections.Generic.List`1 复制的元素的目标位置的一维 System.Array。System.Array
        //     必须具有从零开始的索引。
        //
        // 异常:
        //   T:System.ArgumentNullException:
        //     array 为 null。
        //
        //   T:System.ArgumentException:
        //     源 System.Collections.Generic.List`1 中的元素数大于目标 array 可包含的元素数。
        [TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
        public void CopyTo(T[] array);
        //
        // 摘要:
        //     将整个 System.Collections.Generic.List`1 复制到兼容的一维数组中,从目标数组的指定索引位置开始放置。
        //
        // 参数:
        //   array:
        //     作为从 System.Collections.Generic.List`1 复制的元素的目标位置的一维 System.Array。System.Array
        //     必须具有从零开始的索引。
        //
        //   arrayIndex:
        //     array 中从零开始的索引,从此索引处开始进行复制。
        //
        // 异常:
        //   T:System.ArgumentNullException:
        //     array 为 null。
        //
        //   T:System.ArgumentOutOfRangeException:
        //     arrayIndex 小于 0。
        //
        //   T:System.ArgumentException:
        //     源 System.Collections.Generic.List`1 中的元素数目大于从 arrayIndex 到目标 array 末尾之间的可用空间。
        public void CopyTo(T[] array, int arrayIndex);
        //
        // 摘要:
        //     将一定范围的元素从 System.Collections.Generic.List`1 复制到兼容的一维数组中,从目标数组的指定索引位置开始放置。
        //
        // 参数:
        //   index:
        //     源 System.Collections.Generic.List`1 中复制开始位置的从零开始的索引。
        //
        //   array:
        //     作为从 System.Collections.Generic.List`1 复制的元素的目标位置的一维 System.Array。System.Array
        //     必须具有从零开始的索引。
        //
        //   arrayIndex:
        //     array 中从零开始的索引,从此索引处开始进行复制。
        //
        //   count:
        //     要复制的元素数。
        //
        // 异常:
        //   T:System.ArgumentNullException:
        //     array 为 null。
        //
        //   T:System.ArgumentOutOfRangeException:
        //     index 小于 0。- 或 -arrayIndex 小于 0。- 或 -count 小于 0。
        //
        //   T:System.ArgumentException:
        //     index 等于或大于源 System.Collections.Generic.List`1 的 System.Collections.Generic.List`1.Count。-
        //     或 -从 index 到源 System.Collections.Generic.List`1 的末尾的元素数大于从 arrayIndex 到目标 array
        //     的末尾的可用空间。
        public void CopyTo(int index, T[] array, int arrayIndex, int count);
        //
        // 摘要:
        //     确定 System.Collections.Generic.List`1 是否包含与指定谓词所定义的条件相匹配的元素。
        //
        // 参数:
        //   match:
        //     System.Predicate`1 委托,用于定义要搜索的元素应满足的条件。
        //
        // 返回结果:
        //     如果 System.Collections.Generic.List`1 包含一个或多个与指定谓词所定义的条件相匹配的元素,则为 true;否则为 false。
        //
        // 异常:
        //   T:System.ArgumentNullException:
        //     match 为 null。
        public bool Exists(Predicate<T> match);
        //
        // 摘要:
        //     搜索与指定谓词所定义的条件相匹配的元素,并返回整个 System.Collections.Generic.List`1 中的第一个匹配元素。
        //
        // 参数:
        //   match:
        //     System.Predicate`1 委托,用于定义要搜索的元素的条件。
        //
        // 返回结果:
        //     如果找到与指定谓词定义的条件匹配的第一个元素,则为该元素;否则为类型 T 的默认值。
        //
        // 异常:
        //   T:System.ArgumentNullException:
        //     match 为 null。
        public T Find(Predicate<T> match);
        //
        // 摘要:
        //     检索与指定谓词定义的条件匹配的所有元素。
        //
        // 参数:
        //   match:
        //     System.Predicate`1 委托,用于定义要搜索的元素应满足的条件。
        //
        // 返回结果:
        //     如果找到,则为一个 System.Collections.Generic.List`1,其中包含与指定谓词所定义的条件相匹配的所有元素;否则为一个空 System.Collections.Generic.List`1。
        //
        // 异常:
        //   T:System.ArgumentNullException:
        //     match 为 null。
        public List<T> FindAll(Predicate<T> match);
        //
        // 摘要:
        //     搜索与指定谓词所定义的条件相匹配的元素,并返回整个 System.Collections.Generic.List`1 中第一个匹配元素的从零开始的索引。
        //
        // 参数:
        //   match:
        //     System.Predicate`1 委托,用于定义要搜索的元素的条件。
        //
        // 返回结果:
        //     如果找到与 match 定义的条件相匹配的第一个元素,则为该元素的从零开始的索引;否则为 -1。
        //
        // 异常:
        //   T:System.ArgumentNullException:
        //     match 为 null。
        public int FindIndex(Predicate<T> match);
        //
        // 摘要:
        //     搜索与指定谓词所定义的条件相匹配的元素,并返回 System.Collections.Generic.List`1 中从指定索引到最后一个元素的元素范围内第一个匹配项的从零开始的索引。
        //
        // 参数:
        //   startIndex:
        //     从零开始的搜索的起始索引。
        //
        //   match:
        //     System.Predicate`1 委托,用于定义要搜索的元素的条件。
        //
        // 返回结果:
        //     如果找到与 match 定义的条件相匹配的第一个元素,则为该元素的从零开始的索引;否则为 -1。
        //
        // 异常:
        //   T:System.ArgumentNullException:
        //     match 为 null。
        //
        //   T:System.ArgumentOutOfRangeException:
        //     startIndex 不在 System.Collections.Generic.List`1 的有效索引范围内。
        public int FindIndex(int startIndex, Predicate<T> match);
        //
        // 摘要:
        //     搜索与指定谓词所定义的条件相匹配的一个元素,并返回 System.Collections.Generic.List`1 中从指定的索引开始、包含指定元素个数的元素范围内第一个匹配项的从零开始的索引。
        //
        // 参数:
        //   startIndex:
        //     从零开始的搜索的起始索引。
        //
        //   count:
        //     要搜索的部分中的元素数。
        //
        //   match:
        //     System.Predicate`1 委托,用于定义要搜索的元素的条件。
        //
        // 返回结果:
        //     如果找到与 match 定义的条件相匹配的第一个元素,则为该元素的从零开始的索引;否则为 -1。
        //
        // 异常:
        //   T:System.ArgumentNullException:
        //     match 为 null。
        //
        //   T:System.ArgumentOutOfRangeException:
        //     startIndex 不在 System.Collections.Generic.List`1 的有效索引范围内。- 或 -count 小于 0。- 或
        //     -startIndex 和 count 未指定 System.Collections.Generic.List`1 中的有效部分。
        public int FindIndex(int startIndex, int count, Predicate<T> match);
        //
        // 摘要:
        //     搜索与指定谓词所定义的条件相匹配的元素,并返回整个 System.Collections.Generic.List`1 中的最后一个匹配元素。
        //
        // 参数:
        //   match:
        //     System.Predicate`1 委托,用于定义要搜索的元素的条件。
        //
        // 返回结果:
        //     如果找到,则为与指定谓词所定义的条件相匹配的最后一个元素;否则为类型 T 的默认值。
        //
        // 异常:
        //   T:System.ArgumentNullException:
        //     match 为 null。
        public T FindLast(Predicate<T> match);
        //
        // 摘要:
        //     搜索与指定谓词所定义的条件相匹配的元素,并返回整个 System.Collections.Generic.List`1 中最后一个匹配元素的从零开始的索引。
        //
        // 参数:
        //   match:
        //     System.Predicate`1 委托,用于定义要搜索的元素的条件。
        //
        // 返回结果:
        //     如果找到与 match 定义的条件相匹配的最后一个元素,则为该元素的从零开始的索引;否则为 -1。
        //
        // 异常:
        //   T:System.ArgumentNullException:
        //     match 为 null。
        public int FindLastIndex(Predicate<T> match);
        //
        // 摘要:
        //     搜索与由指定谓词定义的条件相匹配的元素,并返回 System.Collections.Generic.List`1 中从第一个元素到指定索引的元素范围内最后一个匹配项的从零开始的索引。
        //
        // 参数:
        //   startIndex:
        //     向后搜索的从零开始的起始索引。
        //
        //   match:
        //     System.Predicate`1 委托,用于定义要搜索的元素的条件。
        //
        // 返回结果:
        //     如果找到与 match 定义的条件相匹配的最后一个元素,则为该元素的从零开始的索引;否则为 -1。
        //
        // 异常:
        //   T:System.ArgumentNullException:
        //     match 为 null。
        //
        //   T:System.ArgumentOutOfRangeException:
        //     startIndex 不在 System.Collections.Generic.List`1 的有效索引范围内。
        public int FindLastIndex(int startIndex, Predicate<T> match);
        //
        // 摘要:
        //     搜索与指定谓词所定义的条件相匹配的元素,并返回 System.Collections.Generic.List`1 中包含指定元素个数、到指定索引结束的元素范围内最后一个匹配项的从零开始的索引。
        //
        // 参数:
        //   startIndex:
        //     向后搜索的从零开始的起始索引。
        //
        //   count:
        //     要搜索的部分中的元素数。
        //
        //   match:
        //     System.Predicate`1 委托,用于定义要搜索的元素的条件。
        //
        // 返回结果:
        //     如果找到与 match 定义的条件相匹配的最后一个元素,则为该元素的从零开始的索引;否则为 -1。
        //
        // 异常:
        //   T:System.ArgumentNullException:
        //     match 为 null。
        //
        //   T:System.ArgumentOutOfRangeException:
        //     startIndex 不在 System.Collections.Generic.List`1 的有效索引范围内。- 或 -count 小于 0。- 或
        //     -startIndex 和 count 未指定 System.Collections.Generic.List`1 中的有效部分。
        public int FindLastIndex(int startIndex, int count, Predicate<T> match);
        //
        // 摘要:
        //     对 System.Collections.Generic.List`1 的每个元素执行指定操作。
        //
        // 参数:
        //   action:
        //     要对 System.Collections.Generic.List`1 的每个元素执行的 System.Action`1 委托。
        //
        // 异常:
        //   T:System.ArgumentNullException:
        //     action 为 null。
        public void ForEach(Action<T> action);
        //
        // 摘要:
        //     返回循环访问 System.Collections.Generic.List`1 的枚举数。
        //
        // 返回结果:
        //     用于 System.Collections.Generic.List`1 的 System.Collections.Generic.List`1.Enumerator。
        [TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
        public Enumerator GetEnumerator();
        //
        // 摘要:
        //     创建源 System.Collections.Generic.List`1 中的元素范围的浅表副本。
        //
        // 参数:
        //   index:
        //     范围开始处的从零开始的 System.Collections.Generic.List`1 索引。
        //
        //   count:
        //     范围中的元素数。
        //
        // 返回结果:
        //     源 System.Collections.Generic.List`1 中的元素范围的浅表副本。
        //
        // 异常:
        //   T:System.ArgumentOutOfRangeException:
        //     index 小于 0。- 或 -count 小于 0。
        //
        //   T:System.ArgumentException:
        //     index 和 count 不表示 System.Collections.Generic.List`1 中元素的有效范围。
        public List<T> GetRange(int index, int count);
        //
        // 摘要:
        //     搜索指定的对象,并返回整个 System.Collections.Generic.List`1 中第一个匹配项的从零开始的索引。
        //
        // 参数:
        //   item:
        //     要在 System.Collections.Generic.List`1 中定位的对象。对于引用类型,该值可以为 null。
        //
        // 返回结果:
        //     如果在整个 System.Collections.Generic.List`1 中找到 item 的第一个匹配项,则为该项的从零开始的索引;否则为 -1。
        [TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
        public int IndexOf(T item);
        //
        // 摘要:
        //     搜索指定的对象,并返回 System.Collections.Generic.List`1 中从指定索引到最后一个元素的元素范围内第一个匹配项的从零开始的索引。
        //
        // 参数:
        //   item:
        //     要在 System.Collections.Generic.List`1 中定位的对象。对于引用类型,该值可以为 null。
        //
        //   index:
        //     从零开始的搜索的起始索引。空列表中 0(零)为有效值。
        //
        // 返回结果:
        //     如果在 System.Collections.Generic.List`1 中从 index 到最后一个元素的元素范围内找到 item 的第一个匹配项,则为该项的从零开始的索引;否则为
        //     -1。
        //
        // 异常:
        //   T:System.ArgumentOutOfRangeException:
        //     index 不在 System.Collections.Generic.List`1 的有效索引范围内。
        public int IndexOf(T item, int index);
        //
        // 摘要:
        //     搜索指定的对象,并返回 System.Collections.Generic.List`1 中从指定的索引开始并包含指定的元素数的元素范围内第一个匹配项的从零开始的索引。
        //
        // 参数:
        //   item:
        //     要在 System.Collections.Generic.List`1 中定位的对象。对于引用类型,该值可以为 null。
        //
        //   index:
        //     从零开始的搜索的起始索引。空列表中 0(零)为有效值。
        //
        //   count:
        //     要搜索的部分中的元素数。
        //
        // 返回结果:
        //     如果在 System.Collections.Generic.List`1 中从 index 开始并包含 count 个元素的元素范围内找到 item 的第一个匹配项,则为该项的从零开始的索引;否则为
        //     -1。
        //
        // 异常:
        //   T:System.ArgumentOutOfRangeException:
        //     index 不在 System.Collections.Generic.List`1 的有效索引范围内。- 或 -count 小于 0。- 或 -index
        //     和 count 未指定 System.Collections.Generic.List`1 中的有效部分。
        public int IndexOf(T item, int index, int count);
        //
        // 摘要:
        //     将元素插入 System.Collections.Generic.List`1 的指定索引处。
        //
        // 参数:
        //   index:
        //     从零开始的索引,应在该位置插入 item。
        //
        //   item:
        //     要插入的对象。对于引用类型,该值可以为 null。
        //
        // 异常:
        //   T:System.ArgumentOutOfRangeException:
        //     index 小于 0。- 或 -index 大于 System.Collections.Generic.List`1.Count。
        public void Insert(int index, T item);
        //
        // 摘要:
        //     将集合中的某个元素插入 System.Collections.Generic.List`1 的指定索引处。
        //
        // 参数:
        //   index:
        //     应在此处插入新元素的从零开始的索引。
        //
        //   collection:
        //     一个集合,应将其元素插入到 System.Collections.Generic.List`1 中。集合自身不能为 null,但它可以包含为 null 的元素(如果类型
        //     T 为引用类型)。
        //
        // 异常:
        //   T:System.ArgumentNullException:
        //     collection 为 null。
        //
        //   T:System.ArgumentOutOfRangeException:
        //     index 小于 0。- 或 -index 大于 System.Collections.Generic.List`1.Count。
        public void InsertRange(int index, IEnumerable<T> collection);
        //
        // 摘要:
        //     搜索指定的对象,并返回整个 System.Collections.Generic.List`1 中最后一个匹配项的从零开始的索引。
        //
        // 参数:
        //   item:
        //     要在 System.Collections.Generic.List`1 中定位的对象。对于引用类型,该值可以为 null。
        //
        // 返回结果:
        //     如果在整个 System.Collections.Generic.List`1 中找到 item 的最后一个匹配项,则为该项的从零开始的索引;否则为 -1。
        public int LastIndexOf(T item);
        //
        // 摘要:
        //     搜索指定的对象,并返回 System.Collections.Generic.List`1 中从第一个元素到指定索引的元素范围内最后一个匹配项的从零开始的索引。
        //
        // 参数:
        //   item:
        //     要在 System.Collections.Generic.List`1 中定位的对象。对于引用类型,该值可以为 null。
        //
        //   index:
        //     向后搜索的从零开始的起始索引。
        //
        // 返回结果:
        //     如果在 System.Collections.Generic.List`1 中从第一个元素到 index 的元素范围内找到 item 的最后一个匹配项,则为该项的从零开始的索引;否则为
        //     -1。
        //
        // 异常:
        //   T:System.ArgumentOutOfRangeException:
        //     index 不在 System.Collections.Generic.List`1 的有效索引范围内。
        public int LastIndexOf(T item, int index);
        //
        // 摘要:
        //     搜索指定的对象,并返回 System.Collections.Generic.List`1 中包含指定的元素数并在指定索引处结束的元素范围内最后一个匹配项的从零开始的索引。
        //
        // 参数:
        //   item:
        //     要在 System.Collections.Generic.List`1 中定位的对象。对于引用类型,该值可以为 null。
        //
        //   index:
        //     向后搜索的从零开始的起始索引。
        //
        //   count:
        //     要搜索的部分中的元素数。
        //
        // 返回结果:
        //     如果在 System.Collections.Generic.List`1 中包含 count 个元素、在 index 处结尾的元素范围内找到 item
        //     的最后一个匹配项,则为该项的从零开始的索引;否则为 -1。
        //
        // 异常:
        //   T:System.ArgumentOutOfRangeException:
        //     index 不在 System.Collections.Generic.List`1 的有效索引范围内。- 或 -count 小于 0。- 或 -index
        //     和 count 未指定 System.Collections.Generic.List`1 中的有效部分。
        public int LastIndexOf(T item, int index, int count);
        //
        // 摘要:
        //     从 System.Collections.Generic.List`1 中移除特定对象的第一个匹配项。
        //
        // 参数:
        //   item:
        //     要从 System.Collections.Generic.List`1 中移除的对象。对于引用类型,该值可以为 null。
        //
        // 返回结果:
        //     如果成功移除 item,则为 true;否则为 false。如果在 System.Collections.Generic.List`1 中没有找到 item,该方法也会返回
        //     false。
        [TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
        public bool Remove(T item);
        //
        // 摘要:
        //     移除与指定的谓词所定义的条件相匹配的所有元素。
        //
        // 参数:
        //   match:
        //     System.Predicate`1 委托,用于定义要移除的元素应满足的条件。
        //
        // 返回结果:
        //     从 System.Collections.Generic.List`1 中移除的元素的数目。
        //
        // 异常:
        //   T:System.ArgumentNullException:
        //     match 为 null。
        public int RemoveAll(Predicate<T> match);
        //
        // 摘要:
        //     移除 System.Collections.Generic.List`1 的指定索引处的元素。
        //
        // 参数:
        //   index:
        //     要移除的元素的从零开始的索引。
        //
        // 异常:
        //   T:System.ArgumentOutOfRangeException:
        //     index 小于 0。- 或 -index 等于或大于 System.Collections.Generic.List`1.Count。
        public void RemoveAt(int index);
        //
        // 摘要:
        //     从 System.Collections.Generic.List`1 中移除一定范围的元素。
        //
        // 参数:
        //   index:
        //     要移除的元素的范围从零开始的起始索引。
        //
        //   count:
        //     要移除的元素数。
        //
        // 异常:
        //   T:System.ArgumentOutOfRangeException:
        //     index 小于 0。- 或 -count 小于 0。
        //
        //   T:System.ArgumentException:
        //     index 和 count 不表示 System.Collections.Generic.List`1 中元素的有效范围。
        public void RemoveRange(int index, int count);
        //
        // 摘要:
        //     将整个 System.Collections.Generic.List`1 中元素的顺序反转。
        public void Reverse();
        //
        // 摘要:
        //     将指定范围中元素的顺序反转。
        //
        // 参数:
        //   index:
        //     要反转的范围的从零开始的起始索引。
        //
        //   count:
        //     要反转的范围内的元素数。
        //
        // 异常:
        //   T:System.ArgumentOutOfRangeException:
        //     index 小于 0。- 或 -count 小于 0。
        //
        //   T:System.ArgumentException:
        //     index 和 count 不表示 System.Collections.Generic.List`1 中元素的有效范围。
        public void Reverse(int index, int count);
        //
        // 摘要:
        //     使用默认比较器对整个 System.Collections.Generic.List`1 中的元素进行排序。
        //
        // 异常:
        //   T:System.InvalidOperationException:
        //     默认比较器 System.Collections.Generic.Comparer`1.Default 找不到 T 类型的 System.IComparable`1
        //     泛型接口或 System.IComparable 接口的实现。
        public void Sort();
        //
        // 摘要:
        //     使用指定的 System.Comparison`1 对整个 System.Collections.Generic.List`1 中的元素进行排序。
        //
        // 参数:
        //   comparison:
        //     比较元素时要使用的 System.Comparison`1。
        //
        // 异常:
        //   T:System.ArgumentNullException:
        //     comparison 为 null。
        //
        //   T:System.ArgumentException:
        //     在排序过程中,comparison 的实现会导致错误。例如,将某个项与其自身进行比较时,comparison 可能不返回 0。
        public void Sort(Comparison<T> comparison);
        //
        // 摘要:
        //     使用指定的比较器对整个 System.Collections.Generic.List`1 中的元素进行排序。
        //
        // 参数:
        //   comparer:
        //     比较元素时要使用的 System.Collections.Generic.IComparer`1 实现,或者为 null,表示使用默认比较器 System.Collections.Generic.Comparer`1.Default。
        //
        // 异常:
        //   T:System.InvalidOperationException:
        //     comparer 为 null,且默认比较器 System.Collections.Generic.Comparer`1.Default 找不到 T 类型的
        //     System.IComparable`1 泛型接口或 System.IComparable 接口的实现。
        //
        //   T:System.ArgumentException:
        //     comparer 的实现导致排序时出现错误。例如,将某个项与其自身进行比较时,comparer 可能不返回 0。
        public void Sort(IComparer<T> comparer);
        //
        // 摘要:
        //     使用指定的比较器对 System.Collections.Generic.List`1 中某个范围内的元素进行排序。
        //
        // 参数:
        //   index:
        //     要排序的范围的从零开始的起始索引。
        //
        //   count:
        //     要排序的范围的长度。
        //
        //   comparer:
        //     比较元素时要使用的 System.Collections.Generic.IComparer`1 实现,或者为 null,表示使用默认比较器 System.Collections.Generic.Comparer`1.Default。
        //
        // 异常:
        //   T:System.ArgumentOutOfRangeException:
        //     index 小于 0。- 或 -count 小于 0。
        //
        //   T:System.ArgumentException:
        //     index 和 count 未指定 System.Collections.Generic.List`1 中的有效范围。- 或 -comparer 的实现导致排序时出现错误。例如,将某个项与其自身进行比较时,comparer
        //     可能不返回 0。
        //
        //   T:System.InvalidOperationException:
        //     comparer 为 null,且默认比较器 System.Collections.Generic.Comparer`1.Default 找不到 T 类型的
        //     System.IComparable`1 泛型接口或 System.IComparable 接口的实现。
        public void Sort(int index, int count, IComparer<T> comparer);
        //
        // 摘要:
        //     将 System.Collections.Generic.List`1 的元素复制到新数组中。
        //
        // 返回结果:
        //     一个数组,它包含 System.Collections.Generic.List`1 的元素的副本。
        public T[] ToArray();
        //
        // 摘要:
        //     将容量设置为 System.Collections.Generic.List`1 中的实际元素数目(如果该数目小于某个阈值)。
        public void TrimExcess();
        //
        // 摘要:
        //     确定是否 System.Collections.Generic.List`1 中的每个元素都与指定的谓词所定义的条件相匹配。
        //
        // 参数:
        //   match:
        //     System.Predicate`1 委托,定义要据以检查元素的条件。
        //
        // 返回结果:
        //     如果 System.Collections.Generic.List`1 中的每个元素都与指定的谓词所定义的条件相匹配,则为 true;否则为 false。如果列表不包含任何元素,则返回值为
        //     true。
        //
        // 异常:
        //   T:System.ArgumentNullException:
        //     match 为 null。
        public bool TrueForAll(Predicate<T> match);

        //
        // 摘要:
        //     枚举 System.Collections.Generic.List`1 的元素。
        public struct Enumerator : IEnumerator<T>, IDisposable, IEnumerator
        {
            //
            // 摘要:
            //     获取枚举数当前位置的元素。
            //
            // 返回结果:
            //     System.Collections.Generic.List`1 中位于该枚举数当前位置的元素。
            public T Current { get; }

            //
            // 摘要:
            //     释放由 System.Collections.Generic.List`1.Enumerator 使用的所有资源。
            [TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
            public void Dispose();
            //
            // 摘要:
            //     使枚举数前进到 System.Collections.Generic.List`1 的下一个元素。
            //
            // 返回结果:
            //     如果枚举数成功地推进到下一个元素,则为 true;如果枚举数越过集合的结尾,则为 false。
            //
            // 异常:
            //   T:System.InvalidOperationException:
            //     在创建了枚举数后集合被修改了。
            public bool MoveNext();
        }
    }
}

以上就是系统内部已经定义好的一些用法,下面就是自己做的一些demo;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 泛型list
{
    class Program
    {
        static void Main(string[] args)
        {
            List<int> list1=new List<int>();
            //实例一个LIST类;
            list1.Add(1);
            //这个是往线性表里面的第一个数据:list1[0];
            list1.Add(2);
            //这个是往线性表里面的第二个数据:list1[1];
            list1.Add(3);
            //这个是往线性表里面的第三个数据:list1[2];
            list1.Add(4);
            list1.Add(5);
            for (int i = 0; i < list1.Count; i++)
            {
                Console.WriteLine("表里的元素是:"+list1[i]);
            }
            Console.WriteLine(list1.GetType());
            //获取表的数据类型属性;
            Console.WriteLine("表里面已经存储的数据有:"+list1.Count);
            Console.WriteLine("当前表的容量是:"+list1.Capacity);
            //获取表的内存;以四个四个增加
            Console.Read();
        }
    }
}

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值