C#学习追根溯源之集合方法集

时间:2021-10-27 03:54:18

标签:interface method/field

System.Collections命名空间中的枚举器接口(IEnumerator)

***attention field :   object Current{get;}

***interface method: bool MoveNext()

***interface method: void Reset();

using System;
using System.Runtime.InteropServices;
namespace System.Collections
{
    // Summary:
    //     Supports a simple iteration over a nongeneric collection.
    [ComVisible(true)]
    [Guid("496B0ABF-CDEE-11d3-88E8-00902754C43A")]
    public interface IEnumerator
    {
        // Summary:
        //     Gets the current element in the collection.
        //
        // Returns:
        //     The current element in the collection.
        //
        // Exceptions:
        //   System.InvalidOperationException:
        //     The enumerator is positioned before the first element of the collection or
        //     after the last element.
        object Current { get; }

        // Summary:
        //     Advances the enumerator to the next element of the collection.
        //
        // Returns:
        //     true if the enumerator was successfully advanced to the next element; false
        //     if the enumerator has passed the end of the collection.
        //
        // Exceptions:
        //   System.InvalidOperationException:
        //     The collection was modified after the enumerator was created.
        bool MoveNext();
        //
        // Summary:
        //     Sets the enumerator to its initial position, which is before the first element
        //     in the collection.
        //
        // Exceptions:
        //   System.InvalidOperationException:
        //     The collection was modified after the enumerator was created.
        void Reset();
    }
}

2.System.Collections命名空间中的可枚举类型接口IEnumerable

***interface method: GetEnumerator()

using System.Runtime.InteropServices;
namespace System.Collections
{
    // Summary:
    //     Exposes the enumerator, which supports a simple iteration over a non-generic
    //     collection.
    [ComVisible(true)]
    [Guid("496B0ABE-CDEE-11d3-88E8-00902754C43A")]
    public interface IEnumerable
    {
        // Summary:
        //     Returns an enumerator that iterates through a collection.
        //
        // Returns:
        //     An System.Collections.IEnumerator object that can be used to iterate through
        //     the collection.
        [DispId(-4)]
        IEnumerator GetEnumerator();
    }
}

3.System.Collections命名空间中的集合接口(ICollection

***field: int Count{get;}

***field: bool isSynchronized{get;}

***field: object SyncRoot{get;}//同步根

***inteface method: CopyTo(Array array,int index);//attention there is a argument:Array