2.2. Array

Array:ICollection,IList,IStructuralComparable, IStructuralEquatable

3300行,但是只是数组的基本操作并不难理解

最重要的其实就是两个方法吧

BinarySearch()
Sort()

最常用的方法时

IList.this[]
Copy()
Length
ConvertAll()

方法列表

0. publis static void Resize<T>();
    使用Array.Copy来将旧数组复制到新数组 

1. public unsafe static Array CreateInstance();
    调用 private unsafe static extern Array internalCreateInstance()

2. public extern void Copy(....,bool reliable)
    reliable=false 是copy方法的默认行为

3. public static void ConstrainedCopy()
    内部调用Array.Copy
    reliable=true,这是和Copy方法唯一的不同
    当为true时,要么复制成功,要么失败抛出异常,有点事务的意思
    这个方法的特殊就在于他是一个特殊的Copy,值得取个新名字

4. public static extern void Clear(Array,int index,int length);
    将数组设置成默认值(0或null),从index开始
    可以设置将制定的区间设置为默认值

5. public unsafe Object GetValue(params int[] indices);  //获取一维数组指定索引处的值
    内部调用 private unsafe extern void InternlGetReference() 
    因为IList this[]接口的原因,有效的隐藏了调用这个方法的细节,这时一种巨大的好处

   public unsafe void SetValue(object value,params int[] indices); //设置一维数组指定索引处的值
    内部调用 private unsafe extern static void InternalSetValue()

6. GetLowerBound(Int32 )  返回指定维度的第一个元素的索引
    GetUpperBound(Int32 ) 返回数组中指定维度的最后一个元素的索引

7.  public extern int Length{get;}
    public extern int Rank{get;}  返回维度,1维返回1,二维数组返回2
    
8. List,ICollection 的属性 这些常规当时并不有用
    Count,SyncRoot,IsReadOnly,IsFixedSize,IsSynchronized

9. 实现索引访问居然使用的是GetValue,好吧我之前想的是为什么GetValue中为什么不直接用索引,原来是忘了先有鸡还是先有蛋

    public Object IList this[int index]
    {
        get{return GetValue(index);}
        set{SetValue(value,index)};}
    }

10. Add(object value);  //throw not support 
    如果接口定义了但是我就是不想提供这个功能,可以用not support异常

11. 不支持接口的方法有
    IList.Insert()
    IList.Remove()
    IList.RemoveAt()

12. Object.Clone()
    内部调用 Object.MemberwiseClone()

13. CompareTo(Object other,IComparer comparer);

14. GetHashCode 它要怎么实现呢?,也许这里实现并不重要,因为它不需要使用散列表

15. BinarySearch(Array array,int index,int length,Object value,IComparer comparer)
    在该类内部实现

    BinarySearch<T>(T[] array,int index,int legnth,T value,IComparer<T> comparer)
    ArraySortHelper 中定义方法

    其实无论是哪种,二分查询他写的和我写的最大的区别,就是它能想到的情况比我更复杂,它的性能考虑比我更有条理,有套路
17. ConvertAll
    使用委托和for循环,一个一个的转化,然后一个一个的用索引修改
    既然它这样做了,我觉得也没什么不可以啊

18. Find,FindIndex,FindLastIndex,FindAll,Foreach,IndexOf()
    都是O(n)就是普通的循环
    但是比较数据是由一个明显的区分的
    null 用 == 解决
    非null 用 .Equals()  判断,因为在Equals可能没有对other做null的判断,或则抛出了异常,这样写
这就是
原文地址:https://www.cnblogs.com/zhangrCsharp/p/7695572.html