Show / Hide Table of Contents

    Class ArrayExtensions

    Array 扩展方法

    Inheritance
    Object
    ArrayExtensions
    Inherited Members
    Object.Equals(Object)
    Object.Equals(Object, Object)
    Object.GetHashCode()
    Object.GetType()
    Object.MemberwiseClone()
    Object.ReferenceEquals(Object, Object)
    Object.ToString()
    Namespace: Lett.Extensions
    Assembly: Lett.Extensions.dll
    Syntax
    public static class ArrayExtensions

    Methods

    | Improve this Doc View Source

    ClearAll(Array)

    将所有元素设置为元素类型的默认值

    Declaration
    public static void ClearAll(this Array this)
    Parameters
    Type Name Description
    Array this
    Examples
    var s = new[] {"aaa", "bbb"};
    s.ClearAll();
    // s.Length == 2;
    // s[0] == null;
    
    var s = new[] {11, 22};
    s.ClaerAll();
    // s.Length == 2;
    // s[0] == 0;
    // s[1] == 1;
    | Improve this Doc View Source

    ClearAll<T>(T[])

    将所有元素设置为元素类型的默认值

    Declaration
    public static void ClearAll<T>(this T[] this)
    Parameters
    Type Name Description
    T[] this
    Type Parameters
    Name Description
    T

    数组的元素类型

    Examples
    var s = new[] {"aaa", "bbb"};
    s.ClearAll();
    // s.Length == 2;
    // s[0] == null;
    
    var s = new[] {11, 22};
    s.ClaerAll();
    // s.Length == 2;
    // s[0] == 0;
    // s[1] == 1;
    | Improve this Doc View Source

    ContainsIndex(Array, Int32)

    是否包含索引

    Declaration
    public static bool ContainsIndex(this Array this, int index)
    Parameters
    Type Name Description
    Array this
    Int32 index

    索引

    Returns
    Type Description
    Boolean
    Examples
    var s = new[] {"aaa", "bbb"};
    s.ContainsIndex(0);  // true
    s.ContainsIndex(2);  // false
    Exceptions
    Type Condition
    ArgumentNullException

    数组为空

    | Improve this Doc View Source

    ContainsIndex<T>(T[], Int32)

    是否包含索引

    Declaration
    public static bool ContainsIndex<T>(this T[] this, int index)
    Parameters
    Type Name Description
    T[] this
    Int32 index

    索引

    Returns
    Type Description
    Boolean
    Type Parameters
    Name Description
    T

    数组的元素类型

    Examples
    var s = new[] {"aaa", "bbb"};
    s.ContainsIndex(0);  // true
    s.ContainsIndex(2);  // false
    Exceptions
    Type Condition
    ArgumentNullException

    数组为空

    | Improve this Doc View Source

    Find<T>(T[], Predicate<T>)

    返回数组中的第一个匹配元素

    Declaration
    public static T Find<T>(this T[] this, Predicate<T> match)
    Parameters
    Type Name Description
    T[] this
    Predicate<T> match

    用于定义要搜索的元素的条件的谓词

    Returns
    Type Description
    T
    Type Parameters
    Name Description
    T

    数组的元素类型

    Examples
    var rs = new[] {"a", "aa", "bb", "aaa"}.Find(s => s.Length == 2); // "aa"
    Exceptions
    Type Condition
    ArgumentNullException

    match is null.

    | Improve this Doc View Source

    FindAll<T>(T[], Predicate<T>)

    返回数组中所有匹配的元素

    Declaration
    public static T[] FindAll<T>(this T[] this, Predicate<T> match)
    Parameters
    Type Name Description
    T[] this
    Predicate<T> match

    用于定义要搜索的元素的条件的谓词

    Returns
    Type Description
    T[]
    Type Parameters
    Name Description
    T

    数组的元素类型

    Examples
    var rs = new[] {"a", "aa", "bb", "aaa"}.FindAll(s => s.Length == 2); // ["aa","bb"]
    Exceptions
    Type Condition
    ArgumentNullException

    match is null.

    | Improve this Doc View Source

    FindIndex<T>(T[], Int32, Int32, Predicate<T>)

    返回数组中的第一个匹配元素的索引

    Declaration
    public static int FindIndex<T>(this T[] this, int startIndex, int count, Predicate<T> match)
    Parameters
    Type Name Description
    T[] this
    Int32 startIndex

    开始的索引

    Int32 count

    要搜索的部分中的元素数

    Predicate<T> match

    用于定义要搜索的元素的条件的谓词

    Returns
    Type Description
    Int32
    Type Parameters
    Name Description
    T

    数组的元素类型

    Examples
    var rs = new[] {"a", "aa", "bb", "aaa"}.FindIndex(1, 2, ss => ss.Length == 2); // 1
    Exceptions
    Type Condition
    ArgumentNullException

    this 或 match 为空.

    ArgumentOutOfRangeException
    | Improve this Doc View Source

    FindIndex<T>(T[], Int32, Predicate<T>)

    返回数组中的第一个匹配元素的索引

    Declaration
    public static int FindIndex<T>(this T[] this, int startIndex, Predicate<T> match)
    Parameters
    Type Name Description
    T[] this
    Int32 startIndex

    开始的索引

    Predicate<T> match

    用于定义要搜索的元素的条件的谓词

    Returns
    Type Description
    Int32
    Type Parameters
    Name Description
    T

    数组的元素类型

    Examples
    var rs = new[] {"a", "aa", "bb", "aaa"}.FindIndex(2, ss => ss.Length == 2); // 2
    Exceptions
    Type Condition
    ArgumentNullException

    this 或 match 为空.

    ArgumentOutOfRangeException
    | Improve this Doc View Source

    FindIndex<T>(T[], Predicate<T>)

    返回数组中的第一个匹配元素的索引

    Declaration
    public static int FindIndex<T>(this T[] this, Predicate<T> match)
    Parameters
    Type Name Description
    T[] this
    Predicate<T> match

    用于定义要搜索的元素的条件的谓词

    Returns
    Type Description
    Int32
    Type Parameters
    Name Description
    T

    数组的元素类型

    Examples
    var rs = new[] {"a", "aa", "bb", "aaa"}.FindIndex(s => s.Length == 2); // 1
    Exceptions
    Type Condition
    ArgumentNullException

    this 或 match 为空.

    | Improve this Doc View Source

    FindLast<T>(T[], Predicate<T>)

    返回数组中的最后一个匹配元素

    Declaration
    public static T FindLast<T>(this T[] this, Predicate<T> match)
    Parameters
    Type Name Description
    T[] this
    Predicate<T> match

    用于定义要搜索的元素的条件的谓词

    Returns
    Type Description
    T
    Type Parameters
    Name Description
    T

    数组的元素类型

    Examples
    var rs = new[] {"a", "aa", "bb", "aaa"}.FindLast(s => s.Length == 2); // "bb"
    Exceptions
    Type Condition
    ArgumentNullException

    match is null.

    | Improve this Doc View Source

    FindLastIndex<T>(T[], Int32, Int32, Predicate<T>)

    返回数组中的最后一个匹配元素的索引

    Declaration
    public static int FindLastIndex<T>(this T[] this, int startIndex, int count, Predicate<T> match)
    Parameters
    Type Name Description
    T[] this
    Int32 startIndex

    开始的索引

    Int32 count

    要搜索的部分中的元素数

    Predicate<T> match

    用于定义要搜索的元素的条件的谓词

    Returns
    Type Description
    Int32
    Type Parameters
    Name Description
    T

    数组的元素类型

    Examples
    var rs = new[] {"a", "aa", "b", "bb", "bbb", "c"}.FindLastIndex(4,3, s1 => s1.StartsWith("b")); // 4
    Exceptions
    Type Condition
    ArgumentNullException

    this 或 match 为空.

    ArgumentOutOfRangeException
    | Improve this Doc View Source

    FindLastIndex<T>(T[], Int32, Predicate<T>)

    返回数组中的最后一个匹配元素的索引

    Declaration
    public static int FindLastIndex<T>(this T[] this, int startIndex, Predicate<T> match)
    Parameters
    Type Name Description
    T[] this
    Int32 startIndex

    开始的索引

    Predicate<T> match

    用于定义要搜索的元素的条件的谓词

    Returns
    Type Description
    Int32
    Type Parameters
    Name Description
    T

    数组的元素类型

    Examples
    var rs = new[] {"aa", "aaa", "bb", "bb", "bbb", "ccc"}.FindLastIndex(1, s1 => s1.StartsWith("a")); // 1
    Exceptions
    Type Condition
    ArgumentNullException

    this 或 match 为空.

    ArgumentOutOfRangeException
    | Improve this Doc View Source

    FindLastIndex<T>(T[], Predicate<T>)

    返回数组中的最后一个匹配元素的索引

    Declaration
    public static int FindLastIndex<T>(this T[] this, Predicate<T> match)
    Parameters
    Type Name Description
    T[] this
    Predicate<T> match

    用于定义要搜索的元素的条件的谓词

    Returns
    Type Description
    Int32
    Type Parameters
    Name Description
    T

    数组的元素类型

    Examples
    var rs = new[] {"aa", "aaa", "bb", "bb", "bbb", "ccc"}.FindLastIndex(s1 => s1.StartsWith("b")); // 4
    Exceptions
    Type Condition
    ArgumentNullException

    this 或 match 为空

    | Improve this Doc View Source

    Reverse(Array)

    反转数组中元素的顺序

    Declaration
    public static void Reverse(this Array this)
    Parameters
    Type Name Description
    Array this
    Examples
    var s = new[] {"a", "A", "B", "b", "0"};
    s.Reverse(); // {"0", "b", "B", "A", "a"}
    Exceptions
    Type Condition
    ArgumentNullException

    this

    RankException
    | Improve this Doc View Source

    Reverse(Array, Int32, Int32)

    反转数组中元素的顺序

    Declaration
    public static void Reverse(this Array this, int index, int length)
    Parameters
    Type Name Description
    Array this
    Int32 index

    要反转的部分的起始索引

    Int32 length

    要反转的部分中的元素数

    Examples
    var s =  new[] {"a", "A", "B", "b", "0"};
    s.Reverse(2, 3); // {"a", "A", "0", "b", "B"}
    Exceptions
    Type Condition
    ArgumentNullException

    this

    ArgumentOutOfRangeException
    RankException
    ArgumentException
    | Improve this Doc View Source

    Reverse<T>(T[])

    反转数组中元素的顺序

    Declaration
    public static void Reverse<T>(this T[] this)
    Parameters
    Type Name Description
    T[] this
    Type Parameters
    Name Description
    T

    数组的元素类型

    Examples
    var s = new[] {"a", "A", "B", "b", "0"};
    s.Reverse(); // {"0", "b", "B", "A", "a"}
    Exceptions
    Type Condition
    ArgumentNullException

    this

    RankException
    | Improve this Doc View Source

    Reverse<T>(T[], Int32, Int32)

    反转数组中元素的顺序

    Declaration
    public static void Reverse<T>(this T[] this, int index, int length)
    Parameters
    Type Name Description
    T[] this

    当前 Array 泛型接口

    Int32 index

    要反转的部分的起始索引

    Int32 length

    要反转的部分中的元素数

    Type Parameters
    Name Description
    T
    Examples
    var s =  new[] {"a", "A", "B", "b", "0"};
    s.Reverse(2, 3); // {"a", "A", "0", "b", "B"}
    Exceptions
    Type Condition
    ArgumentNullException

    this

    ArgumentOutOfRangeException
    RankException
    ArgumentException
    | Improve this Doc View Source

    Sort(Array)

    排序

    Declaration
    public static void Sort(this Array this)
    Parameters
    Type Name Description
    Array this

    当前 Array

    Examples
    var s = new[] {"a", "b", "c", "d"};
    s.Sort(); // {"a", "b", "c", "d"}
    Exceptions
    Type Condition
    ArgumentNullException

    this

    RankException
    InvalidOperationException
    | Improve this Doc View Source

    Sort(Array, IComparer)

    排序

    Declaration
    public static void Sort(this Array this, IComparer comparer)
    Parameters
    Type Name Description
    Array this
    IComparer comparer

    比较元素时使用的 IComparer<T> 泛型接口实现

    如果为 null,则使用每个元素的 IComparable<T> 泛型接口实现

    Examples
    var s = new[] {"aa", "AA", "A"};
    s.Sort(StringComparer.Ordinal); // {"A", "AA", "a"}
    Exceptions
    Type Condition
    ArgumentNullException

    this

    RankException
    InvalidOperationException
    ArgumentException
    | Improve this Doc View Source

    Sort(Array, Int32, Int32)

    排序

    Declaration
    public static void Sort(this Array this, int index, int length)
    Parameters
    Type Name Description
    Array this
    Int32 index

    排序范围的起始索引

    Int32 length

    排序范围内的元素数

    Examples
    var s = new[] {"aa", "AA", "A"};
    s.Sort(StringComparer.CurrentCulture); // {"A", "aa", "AA"}
    Exceptions
    Type Condition
    ArgumentNullException

    this

    ArgumentOutOfRangeException

    indexlength

    ArgumentException

    indexlength

    InvalidOperationException
    | Improve this Doc View Source

    Sort(Array, Int32, Int32, IComparer)

    排序

    Declaration
    public static void Sort(this Array this, int index, int length, IComparer comparer)
    Parameters
    Type Name Description
    Array this
    Int32 index

    排序范围的起始索引

    Int32 length

    排序范围内的元素数

    IComparer comparer

    比较元素时使用的 IComparer<T> 泛型接口实现

    如果为 null,则使用每个元素的 IComparable<T> 泛型接口实现

    Examples
    var s = new[] {"BB", "aa", "CCC", "ccc", "00"};
    s.Sort(2, 3, StringComparer.CurrentCulture); // {"BB", "aa", "00", "ccc", "CCC"}
    Exceptions
    Type Condition
    ArgumentNullException

    this

    RankException

    this

    ArgumentOutOfRangeException

    indexlength

    ArgumentException

    indexlength

    InvalidOperationException
    | Improve this Doc View Source

    Sort<T>(T[])

    排序

    Declaration
    public static void Sort<T>(this T[] this)
    Parameters
    Type Name Description
    T[] this
    Type Parameters
    Name Description
    T

    数组的元素类型

    Examples
    var s = new[] {"a", "b", "c", "d"};
    s.Sort(); // {"a", "b", "c", "d"}
    Exceptions
    Type Condition
    ArgumentNullException

    this

    RankException
    InvalidOperationException
    | Improve this Doc View Source

    Sort<T>(T[], IComparer)

    排序

    Declaration
    public static void Sort<T>(this T[] this, IComparer comparer)
    Parameters
    Type Name Description
    T[] this
    IComparer comparer

    比较元素时使用的 IComparer<T> 泛型接口实现

    如果为 null,则使用每个元素的 IComparable<T> 泛型接口实现

    Type Parameters
    Name Description
    T

    数组的元素类型

    Examples
    var s = new[] {"aa", "AA", "A"};
    s.Sort(StringComparer.Ordinal); // {"A", "AA", "a"}
    Exceptions
    Type Condition
    ArgumentNullException

    this

    RankException
    InvalidOperationException
    ArgumentException
    | Improve this Doc View Source

    Sort<T>(T[], Int32, Int32)

    排序

    Declaration
    public static void Sort<T>(this T[] this, int index, int length)
    Parameters
    Type Name Description
    T[] this
    Int32 index

    排序范围的起始索引

    Int32 length

    排序范围内的元素数

    Type Parameters
    Name Description
    T

    数组的元素类型

    Examples
    var s = new[] {"aa", "AA", "A"};
    s.Sort(StringComparer.CurrentCulture); // {"A", "aa", "AA"}
    Exceptions
    Type Condition
    ArgumentNullException

    this

    ArgumentOutOfRangeException

    indexlength

    ArgumentException

    indexlength

    InvalidOperationException
    | Improve this Doc View Source

    Sort<T>(T[], Int32, Int32, IComparer)

    排序

    Declaration
    public static void Sort<T>(this T[] this, int index, int length, IComparer comparer)
    Parameters
    Type Name Description
    T[] this
    Int32 index

    排序范围的起始索引

    Int32 length

    排序范围内的元素数

    IComparer comparer

    比较元素时使用的 IComparer<T> 泛型接口实现;如果为 null,则使用每个元素的 IComparable<T> 泛型接口实现

    Type Parameters
    Name Description
    T

    数组的元素类型

    Examples
    var s = new[] {"BB", "aa", "CCC", "ccc", "00"};
    s.Sort(2, 3, StringComparer.CurrentCulture); // {"BB", "aa", "00", "ccc", "CCC"}
    Exceptions
    Type Condition
    ArgumentNullException

    this

    RankException

    this

    ArgumentOutOfRangeException

    indexlength

    ArgumentException

    indexlength

    InvalidOperationException
    • Improve this Doc
    • View Source
    Back to top Copyright (c) 2019 viacooky. All rights reserved.