Array 类

定义

提供一些方法,用于创建、处理、搜索数组并对数组进行排序,从而充当公共语言运行时中所有数组的基类。

public ref class Array abstract : System::Collections::IList, System::Collections::IStructuralComparable, System::Collections::IStructuralEquatable
public ref class Array abstract : ICloneable, System::Collections::IList, System::Collections::IStructuralComparable, System::Collections::IStructuralEquatable
public ref class Array abstract : ICloneable, System::Collections::IList
public abstract class Array : System.Collections.IList, System.Collections.IStructuralComparable, System.Collections.IStructuralEquatable
public abstract class Array : ICloneable, System.Collections.IList, System.Collections.IStructuralComparable, System.Collections.IStructuralEquatable
[System.Serializable]
public abstract class Array : ICloneable, System.Collections.IList
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public abstract class Array : ICloneable, System.Collections.IList
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public abstract class Array : ICloneable, System.Collections.IList, System.Collections.IStructuralComparable, System.Collections.IStructuralEquatable
type Array = class
    interface ICollection
    interface IEnumerable
    interface IList
    interface IStructuralComparable
    interface IStructuralEquatable
type Array = class
    interface ICollection
    interface IEnumerable
    interface IList
    interface IStructuralComparable
    interface IStructuralEquatable
    interface ICloneable
[<System.Serializable>]
type Array = class
    interface ICloneable
    interface IList
    interface ICollection
    interface IEnumerable
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type Array = class
    interface ICloneable
    interface IList
    interface ICollection
    interface IEnumerable
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type Array = class
    interface ICloneable
    interface IList
    interface ICollection
    interface IEnumerable
    interface IStructuralComparable
    interface IStructuralEquatable
type Array = class
    interface IList
    interface ICollection
    interface IEnumerable
    interface IStructuralComparable
    interface IStructuralEquatable
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type Array = class
    interface ICloneable
    interface ICollection
    interface IList
    interface IEnumerable
    interface IStructuralComparable
    interface IStructuralEquatable
Public MustInherit Class Array
Implements IList, IStructuralComparable, IStructuralEquatable
Public MustInherit Class Array
Implements ICloneable, IList, IStructuralComparable, IStructuralEquatable
Public MustInherit Class Array
Implements ICloneable, IList
继承
Array
属性
实现

示例

下面的代码示例演示如何 Array.Copy 在整数类型的数组和 类型的 Object数组之间复制元素。

using namespace System;

void PrintValues(array<Object^>^myArr);
void PrintValues(array<int>^myArr);
void main()
{
    // Creates and initializes a new int array and a new Object array.
    array<int>^myIntArray = { 1,2,3,4,5 };
    array<Object^>^myObjArray = { 26,27,28,29,30 };

    // Prints the initial values of both arrays.
    Console::WriteLine("Initially:");
    Console::Write("int array:   ");
    PrintValues(myIntArray);
    Console::Write("Object array:");
    PrintValues(myObjArray);

    // Copies the first two elements from the int array to the Object array.
    System::Array::Copy(myIntArray, myObjArray, 2);

    // Prints the values of the modified arrays.
    Console::WriteLine("\nAfter copying the first two elements of the int array to the Object array:");
    Console::Write("int array:   ");
    PrintValues(myIntArray);
    Console::Write("Object array:");
    PrintValues(myObjArray);

    // Copies the last two elements from the Object array to the int array.
    System::Array::Copy(myObjArray, myObjArray->GetUpperBound(0) - 1, myIntArray, myIntArray->GetUpperBound(0) - 1, 2);

    // Prints the values of the modified arrays.
    Console::WriteLine("\nAfter copying the last two elements of the Object array to the int array:");
    Console::Write("int array:   ");
    PrintValues(myIntArray);
    Console::Write("Object array:");
    PrintValues(myObjArray);
}

void PrintValues(array<Object^>^myArr)
{
    for (int i = 0; i < myArr->Length; i++)
    {
        Console::Write("\t{0}", myArr[i]);

    }
    Console::WriteLine();
}

void PrintValues(array<int>^myArr)
{
    for (int i = 0; i < myArr->Length; i++)
    {
        Console::Write("\t{0}", myArr[i]);

    }
    Console::WriteLine();
}


/*
This code produces the following output.

Initially:
int array:       1    2    3    4    5
Object array:    26    27    28    29    30
After copying the first two elements of the int array to the Object array:
int array:       1    2    3    4    5
Object array:    1    2    28    29    30
After copying the last two elements of the Object array to the int array:
int array:       1    2    3    29    30
Object array:    1    2    28    29    30
*/
open System

let printValues myArr =
    for i in myArr do
        printf $"\t{i}"
    printfn ""

// Creates and initializes a new integer array and a new Object array.
let myIntArray = [| 1..5 |]
let myObjArray = [| 26..30 |]

// Prints the initial values of both arrays.
printfn "Initially,"
printf "integer array:"
printValues myIntArray
printfn "Object array: "
printValues myObjArray

// Copies the first two elements from the integer array to the Object array.
Array.Copy(myIntArray, myObjArray, 2)

// Prints the values of the modified arrays.
printfn "\nAfter copying the first two elements of the integer array to the Object array,"
printf "integer array:"
printValues myIntArray
printf"Object array: "
printValues myObjArray

// Copies the last two elements from the Object array to the integer array.
Array.Copy(myObjArray, myObjArray.GetUpperBound 0 - 1, myIntArray, myIntArray.GetUpperBound 0 - 1, 2)

// Prints the values of the modified arrays.
printfn $"\nAfter copying the last two elements of the Object array to the integer array,"
printf "integer array:"
printValues myIntArray
printf "Object array: "
printValues myObjArray


// This code produces the following output.
//     Initially,
//     integer array:  1       2       3       4       5
//     Object array:   26      27      28      29      30
//     
//     After copying the first two elements of the integer array to the Object array,
//     integer array:  1       2       3       4       5
//     Object array:   1       2       28      29      30
//     
//     After copying the last two elements of the Object array to the integer array,
//     integer array:  1       2       3       29      30
//     Object array:   1       2       28      29      30
using System;
public class SamplesArray
{

    public static void Main()
    {

        // Creates and initializes a new integer array and a new Object array.
        int[] myIntArray = new int[5] { 1, 2, 3, 4, 5 };
        Object[] myObjArray = new Object[5] { 26, 27, 28, 29, 30 };

        // Prints the initial values of both arrays.
        Console.WriteLine("Initially,");
        Console.Write("integer array:");
        PrintValues(myIntArray);
        Console.Write("Object array: ");
        PrintValues(myObjArray);

        // Copies the first two elements from the integer array to the Object array.
        System.Array.Copy(myIntArray, myObjArray, 2);

        // Prints the values of the modified arrays.
        Console.WriteLine("\nAfter copying the first two elements of the integer array to the Object array,");
        Console.Write("integer array:");
        PrintValues(myIntArray);
        Console.Write("Object array: ");
        PrintValues(myObjArray);

        // Copies the last two elements from the Object array to the integer array.
        System.Array.Copy(myObjArray, myObjArray.GetUpperBound(0) - 1, myIntArray, myIntArray.GetUpperBound(0) - 1, 2);

        // Prints the values of the modified arrays.
        Console.WriteLine("\nAfter copying the last two elements of the Object array to the integer array,");
        Console.Write("integer array:");
        PrintValues(myIntArray);
        Console.Write("Object array: ");
        PrintValues(myObjArray);
    }

    public static void PrintValues(Object[] myArr)
    {
        foreach (Object i in myArr)
        {
            Console.Write("\t{0}", i);
        }
        Console.WriteLine();
    }

    public static void PrintValues(int[] myArr)
    {
        foreach (int i in myArr)
        {
            Console.Write("\t{0}", i);
        }
        Console.WriteLine();
    }
}
/*
This code produces the following output.

Initially,
integer array:  1       2       3       4       5
Object array:   26      27      28      29      30

After copying the first two elements of the integer array to the Object array,
integer array:  1       2       3       4       5
Object array:   1       2       28      29      30

After copying the last two elements of the Object array to the integer array,
integer array:  1       2       3       29      30
Object array:   1       2       28      29      30
*/
Public Class SamplesArray

    Public Shared Sub Main()

        ' Creates and initializes a new integer array and a new Object array.
        Dim myIntArray() As Integer = {1, 2, 3, 4, 5}
        Dim myObjArray() As Object = {26, 27, 28, 29, 30}

        ' Prints the initial values of both arrays.
        Console.WriteLine("Initially:")
        Console.Write("integer array:")
        PrintValues(myIntArray)
        Console.Write("Object array: ")
        PrintValues(myObjArray)

        ' Copies the first two elements from the integer array to the Object array.
        System.Array.Copy(myIntArray, myObjArray, 2)

        ' Prints the values of the modified arrays.
        Console.WriteLine(ControlChars.NewLine + "After copying the first two" _
           + " elements of the integer array to the Object array:")
        Console.Write("integer array:")
        PrintValues(myIntArray)
        Console.Write("Object array: ")
        PrintValues(myObjArray)

        ' Copies the last two elements from the Object array to the integer array.
        System.Array.Copy(myObjArray, myObjArray.GetUpperBound(0) - 1, myIntArray,
           myIntArray.GetUpperBound(0) - 1, 2)

        ' Prints the values of the modified arrays.
        Console.WriteLine(ControlChars.NewLine + "After copying the last two" _
           + " elements of the Object array to the integer array:")
        Console.Write("integer array:")
        PrintValues(myIntArray)
        Console.Write("Object array: ")
        PrintValues(myObjArray)
    End Sub

    Public Overloads Shared Sub PrintValues(myArr() As Object)
        Dim i As Object
        For Each i In myArr
            Console.Write(ControlChars.Tab + "{0}", i)
        Next i
        Console.WriteLine()
    End Sub

    Public Overloads Shared Sub PrintValues(myArr() As Integer)
        Dim i As Integer
        For Each i In myArr
            Console.Write(ControlChars.Tab + "{0}", i)
        Next i
        Console.WriteLine()
    End Sub
End Class

' This code produces the following output.
' 
' Initially:
' integer array:  1       2       3       4       5
' Object array:   26      27      28      29      30
' 
' After copying the first two elements of the integer array to the Object array:
' integer array:  1       2       3       4       5
' Object array:   1       2       28      29      30
' 
' After copying the last two elements of the Object array to the integer array:
' integer array:  1       2       3       29      30
' Object array:   1       2       28      29      30

下面的代码示例创建并初始化 , Array 并显示其属性和元素。

using namespace System;
void PrintValues(Array^ myArr);
void main()
{
   // Creates and initializes a new three-dimensional Array instance of type Int32.
   Array^ myArr = Array::CreateInstance( Int32::typeid, 2, 3, 4 );
   for ( int i = myArr->GetLowerBound( 0 ); i <= myArr->GetUpperBound( 0 ); i++ )
   {
      for ( int j = myArr->GetLowerBound( 1 ); j <= myArr->GetUpperBound( 1 ); j++ )
      {
         for ( int k = myArr->GetLowerBound( 2 ); k <= myArr->GetUpperBound( 2 ); k++ )
            myArr->SetValue( (i * 100) + (j * 10) + k, i, j, k );

      }
   }
   
   // Displays the properties of the Array.
   Console::WriteLine(  "The Array instance has {0} dimension(s) and a total of {1} elements.", myArr->Rank, myArr->Length );
   Console::WriteLine(  "\tLength\tLower\tUpper" );
   for ( int i = 0; i < myArr->Rank; i++ )
   {
      Console::Write(  "{0}:\t{1}", i, myArr->GetLength( i ) );
      Console::WriteLine(  "\t{0}\t{1}", myArr->GetLowerBound( i ), myArr->GetUpperBound( i ) );

   }
   Console::WriteLine(  "The Array instance contains the following values:" );
   PrintValues( myArr );
}

void PrintValues( Array^ myArr )
{
   System::Collections::IEnumerator^ myEnumerator = myArr->GetEnumerator();
   int i = 0;
   int cols = myArr->GetLength( myArr->Rank - 1 );
   while ( myEnumerator->MoveNext() )
   {
      if ( i < cols )
            i++;
      else
      {
         Console::WriteLine();
         i = 1;
      }

      Console::Write(  "\t{0}", myEnumerator->Current );
   }

   Console::WriteLine();
}

/* 
 This code produces the following output.
 
 The Array instance has 3 dimension(s) and a total of 24 elements.
     Length    Lower    Upper
 0:    2    0    1
 1:    3    0    2
 2:    4    0    3
 The Array instance contains the following values:
     0    1    2    3
     10    11    12    13
     20    21    22    23
     100    101    102    103
     110    111    112    113
     120    121    122    123
 */
open System

let printValues (myArray: Array) =
    let mutable i = 0
    let cols = myArray.GetLength(myArray.Rank - 1)
    for item in myArray do
        if i < cols then
            i <- i + 1
        else
            printfn ""
            i <- 1;
        printf $"\t{item}"
    printfn ""

// Creates and initializes a new three-dimensional Array of type int.
let myArr = Array.CreateInstance(typeof<int>, 2, 3, 4)
for i = myArr.GetLowerBound 0 to myArr.GetUpperBound 0 do
    for j = myArr.GetLowerBound 1 to myArr.GetUpperBound 1 do
        for k = myArr.GetLowerBound 2 to myArr.GetUpperBound 2 do
            myArr.SetValue(i * 100 + j * 10 + k, i, j, k)

// Displays the properties of the Array.
printfn $"The Array has {myArr.Rank} dimension(s) and a total of {myArr.Length} elements."
printfn $"\tLength\tLower\tUpper"

for i = 0 to myArr.Rank - 1 do
    printf $"{i}:\t{myArr.GetLength i}"
    printfn $"\t{myArr.GetLowerBound i}\t{myArr.GetUpperBound i}"

// Displays the contents of the Array.
printfn "The Array contains the following values:"
printValues myArr

// This code produces the following output.
// The Array has 3 dimension(s) and a total of 24 elements.
//     Length    Lower    Upper
// 0:  2    0    1
// 1:  3    0    2
// 2:  4    0    3
//
// The Array contains the following values:
//    0      1      2      3
//    10     11     12     13
//    20     21     22     23
//    100    101    102    103
//    110    111    112    113
//    120    121    122    123
// Creates and initializes a new three-dimensional Array of type int.
Array myArr = Array.CreateInstance(typeof(int), 2, 3, 4);
for (int i = myArr.GetLowerBound(0); i <= myArr.GetUpperBound(0); i++)
{
    for (int j = myArr.GetLowerBound(1); j <= myArr.GetUpperBound(1); j++)
    {
        for (int k = myArr.GetLowerBound(2); k <= myArr.GetUpperBound(2); k++)
        {
            myArr.SetValue((i * 100) + (j * 10) + k, i, j, k);
        }
    }
}

// Displays the properties of the Array.
Console.WriteLine("The Array has {0} dimension(s) and a total of {1} elements.", myArr.Rank, myArr.Length);
Console.WriteLine("\tLength\tLower\tUpper");
for (int i = 0; i < myArr.Rank; i++)
{
    Console.Write("{0}:\t{1}", i, myArr.GetLength(i));
    Console.WriteLine("\t{0}\t{1}", myArr.GetLowerBound(i), myArr.GetUpperBound(i));
}

// Displays the contents of the Array.
Console.WriteLine("The Array contains the following values:");
PrintValues(myArr);

void PrintValues(Array myArray)
{
    System.Collections.IEnumerator myEnumerator = myArray.GetEnumerator();
    int i = 0;
    int cols = myArray.GetLength(myArray.Rank - 1);
    while (myEnumerator.MoveNext())
    {
        if (i < cols)
        {
            i++;
        }
        else
        {
            Console.WriteLine();
            i = 1;
        }
        Console.Write("\t{0}", myEnumerator.Current);
    }
    Console.WriteLine();
}
// This code produces the following output.

// The Array has 3 dimension(s) and a total of 24 elements.
//     Length    Lower    Upper
// 0:  2    0    1
// 1:  3    0    2
// 2:  4    0    3
//
// The Array contains the following values:
//    0      1      2      3
//    10     11     12     13
//    20     21     22     23
//    100    101    102    103
//    110    111    112    113
//    120    121    122    123
Public Class SamplesArray2

    Public Shared Sub Main()

        ' Creates and initializes a new three-dimensional Array of
        ' type Int32.
        Dim myArr As Array = Array.CreateInstance(GetType(Int32), 2, 3, 4)
        Dim i As Integer
        For i = myArr.GetLowerBound(0) To myArr.GetUpperBound(0)
            Dim j As Integer
            For j = myArr.GetLowerBound(1) To myArr.GetUpperBound(1)
                Dim k As Integer
                For k = myArr.GetLowerBound(2) To myArr.GetUpperBound(2)
                    myArr.SetValue(i * 100 + j * 10 + k, i, j, k)
                Next k
            Next j
        Next i ' Displays the properties of the Array.
        Console.WriteLine("The Array has {0} dimension(s) and a " _
           + "total of {1} elements.", myArr.Rank, myArr.Length)
        Console.WriteLine(ControlChars.Tab + "Length" + ControlChars.Tab _
           + "Lower" + ControlChars.Tab + "Upper")
        For i = 0 To myArr.Rank - 1
            Console.Write("{0}:" + ControlChars.Tab + "{1}", i,
               myArr.GetLength(i))
            Console.WriteLine(ControlChars.Tab + "{0}" + ControlChars.Tab _
               + "{1}", myArr.GetLowerBound(i), myArr.GetUpperBound(i))
        Next i

        ' Displays the contents of the Array.
        Console.WriteLine("The Array contains the following values:")
        PrintValues(myArr)
    End Sub

    Public Shared Sub PrintValues(myArr As Array)
        Dim myEnumerator As System.Collections.IEnumerator =
           myArr.GetEnumerator()
        Dim i As Integer = 0
        Dim cols As Integer = myArr.GetLength(myArr.Rank - 1)
        While myEnumerator.MoveNext()
            If i < cols Then
                i += 1
            Else
                Console.WriteLine()
                i = 1
            End If
            Console.Write(ControlChars.Tab + "{0}", myEnumerator.Current)
        End While
        Console.WriteLine()
    End Sub
End Class

' This code produces the following output.
' 
' The Array has 3 dimension(s) and a total of 24 elements.
'     Length    Lower    Upper
' 0:    2    0    1
' 1:    3    0    2
' 2:    4    0    3
' The Array contains the following values:
'     0    1    2    3
'     10    11    12    13
'     20    21    22    23
'     100    101    102    103
'     110    111    112    113
'     120    121    122    123

注解

Array 不是命名空间的一 System.Collections 部分。 但是,它仍被视为集合,因为它基于 IList 接口。

Array 是支持数组的语言实现的基类。 但是,只有系统和编译器才能显式从 Array 类派生。 用户应使用语言提供的数组构造。

元素是 中的 Array值。 的 Array 长度是它可以包含的元素总数。 的 Array 下限是其第一个元素的索引。 Array可以具有任何下限,但默认情况下其下限为零。 使用 CreateInstance创建 类的Array实例时,可以定义不同的下限。 对于每个维度,多维 Array 可以有不同的边界。 数组最多可以有 32 个维度。

与命名空间中的 System.Collections 类不同, Array 具有固定的容量。 若要增加容量,必须创建一个具有所需容量的新 Array 对象,将元素从旧 Array 对象复制到新对象,然后删除旧的 Array

数组大小限制为总共 40 亿个元素,对于字节数组和单字节结构数组) ,任何给定维度 (0X7FFFFFC7的最大索引为 0X7FEFFFFF。

仅限.NET Framework:默认情况下,的最大大小Array为 2 GB (GB) 。 在 64 位环境中,可以通过在运行时环境中将 gcAllowVeryLargeObjects 配置元素的 属性设置为 enabledtrue避免大小限制。

一维数组实现 System.Collections.Generic.IList<T>System.Collections.Generic.ICollection<T>System.Collections.Generic.IReadOnlyList<T>System.Collections.Generic.IEnumerable<T>System.Collections.Generic.IReadOnlyCollection<T> 泛型接口。 实现在运行时提供给数组,因此,泛型接口不会出现在 类的声明语法中 Array 。 此外,没有接口成员的引用主题,这些成员只能通过将数组强制转换为泛型接口类型 (显式接口实现) 进行访问。 将数组强制转换为其中一个接口时,需要注意的关键是添加、插入或删除元素的成员会引发 NotSupportedException

Type 对象提供有关数组类型声明的信息。 Array 具有相同数组类型的 对象共享同一 Type 对象。

Type.IsArrayType.GetElementType 可能不会返回预期的结果, Array 因为如果将数组强制转换为 类型 Array,则结果为 对象,而不是数组。 也就是说, typeof(System.Array).IsArray 返回 false, 返回 typeof(System.Array).GetElementTypenull

方法 Array.Copy 不仅在相同类型的数组之间复制元素,还会在不同类型的标准数组之间复制元素;它会自动处理类型转换。

某些方法(如 CreateInstanceCopyCopyToGetValue、 和 SetValue)提供重载,这些重载接受 64 位整数作为参数,以适应大容量数组。 LongLengthGetLongLength 返回指示数组长度的 64 位整数。

Array不保证进行排序。 必须先对 进行排序 Array ,然后才能执行 (操作,例如 BinarySearch 需要 Array 排序的) 。

Array不支持在本机代码中使用指针对象,并且会为多种方法引发 。NotSupportedException

属性

IsFixedSize

获取一个值,该值指示 Array 是否具有固定大小。

IsReadOnly

获取一个值,该值指示 Array 是否为只读。

IsSynchronized

获取一个值,该值指示是否同步对 Array 的访问(线程安全)。

Length

获取 Array 的所有维度中的元素总数。

LongLength

获取一个 64 位整数,该整数表示 Array 的所有维数中元素的总数。

MaxLength

获取数组中可能包含的最大元素数。

Rank

获取 Array 的秩(维数)。 例如,一维数组返回 1,二维数组返回 2,依次类推。

SyncRoot

获取可用于同步对 Array 的访问的对象。

方法

AsReadOnly<T>(T[])

返回指定数组的只读包装。

BinarySearch(Array, Int32, Int32, Object)

使用由一维排序数组中每个元素和指定的值实现的 IComparable 接口,在该数组的一个元素范围内搜索值。

BinarySearch(Array, Int32, Int32, Object, IComparer)

使用指定 IComparer 接口,在一维排序数组的某个元素范围中搜索值。

BinarySearch(Array, Object)

使用由数组中每个元素和指定对象实现的 IComparable 接口,在整个一维排序数组中搜索特定元素。

BinarySearch(Array, Object, IComparer)

使用指定 IComparer 接口,在整个一维排序数组中搜索值。

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

使用由 Array 中每个元素和指定值实现的 IComparable<T> 泛型接口,在一维排序数组的某个元素范围中搜索值。

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

使用指定 IComparer<T> 泛型接口,在一维排序数组的某个元素范围中搜索值。

BinarySearch<T>(T[], T)

使用由 Array 中每个元素和指定对象实现的 IComparable<T> 泛型接口,在整个一维排序数组中搜索特定元素。

BinarySearch<T>(T[], T, IComparer<T>)

使用指定 IComparer<T> 泛型接口,在整个一维排序数组中搜索值。

Clear(Array)

清除数组的内容。

Clear(Array, Int32, Int32)

将数组中的某个范围的元素设置为每个元素类型的默认值。

Clone()

创建 Array 的浅表副本。

ConstrainedCopy(Array, Int32, Array, Int32, Int32)

复制 Array 中的一系列元素(从指定的源索引开始),并将它们粘贴到另一 Array 中(从指定的目标索引开始)。 保证在复制未成功完成的情况下撤消所有更改。

ConvertAll<TInput,TOutput>(TInput[], Converter<TInput,TOutput>)

将一种类型的数组转换为另一种类型的数组。

Copy(Array, Array, Int32)

从第一个元素开始复制 Array 中的一系列元素,将它们粘贴到另一 Array 中(从第一个元素开始)。 长度指定为 32 位整数。

Copy(Array, Array, Int64)

从第一个元素开始复制 Array 中的一系列元素,将它们粘贴到另一 Array 中(从第一个元素开始)。 长度指定为 64 位整数。

Copy(Array, Int32, Array, Int32, Int32)

复制 Array 中的一系列元素(从指定的源索引开始),并将它们粘贴到另一 Array 中(从指定的目标索引开始)。 长度和索引指定为 32 位整数。

Copy(Array, Int64, Array, Int64, Int64)

复制 Array 中的一系列元素(从指定的源索引开始),并将它们粘贴到另一 Array 中(从指定的目标索引开始)。 长度和索引指定为 64 位整数。

CopyTo(Array, Int32)

从指定的目标数组索引处开始,将当前一维数组的所有元素复制到指定的一维数组中。 索引指定为 32 位整数。

CopyTo(Array, Int64)

从指定的目标数组索引处开始,将当前一维数组的所有元素复制到指定的一维数组中。 索引指定为 64 位整数。

CreateInstance(Type, Int32)

创建使用从零开始的索引、具有指定 Type 和长度的一维 Array

CreateInstance(Type, Int32, Int32)

创建使用从零开始的索引、具有指定 Type 和维长的二维 Array

CreateInstance(Type, Int32, Int32, Int32)

创建使用从零开始的索引、具有指定 Type 和维长的三维 Array

CreateInstance(Type, Int32[])

创建索引从零开始、具有指定 Type 和维长的多维 Array。 维的长度在一个 32 位整数数组中指定。

CreateInstance(Type, Int32[], Int32[])

创建具有指定下限、指定 Type 和维长的多维 Array

CreateInstance(Type, Int64[])

创建索引从零开始、具有指定 Type 和维长的多维 Array。 维度的长度在一个 64 位整数数组中指定。

Empty<T>()

返回一个空数组。

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
Exists<T>(T[], Predicate<T>)

确定指定数组包含的元素是否与指定谓词定义的条件匹配。

Fill<T>(T[], T)

将类型为 T 的给定 value 分配给指定的 array 的每个元素。

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

将类型为 T 的给定 value 分配给指定的 array 的元素,其位于索引的 startIndex(含)到后续 count 数的范围内。

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

搜索与指定谓词所定义的条件相匹配的元素,并返回整个 Array 中的第一个匹配元素。

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

检索与指定谓词定义的条件匹配的所有元素。

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

搜索与指定谓词所定义的条件相匹配的一个元素,并返回 Array 中从指定的索引开始、包含指定元素个数的元素范围内第一个匹配项的从零开始的索引。

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

搜索与指定谓词所定义的条件相匹配的元素,并返回 Array 中从指定索引到最后一个元素的元素范围内第一个匹配项的从零开始的索引。

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

搜索与指定谓词所定义的条件相匹配的元素,并返回整个 Array 中第一个匹配元素的从零开始的索引。

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

搜索与指定谓词所定义的条件相匹配的元素,并返回整个 Array 中的最后一个匹配元素。

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

搜索与指定谓词所定义的条件相匹配的元素,并返回 Array 中包含指定元素个数、到指定索引结束的元素范围内最后一个匹配项的从零开始的索引。

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

搜索与由指定谓词定义的条件相匹配的元素,并返回 Array 中从第一个元素到指定索引的元素范围内最后一个匹配项的从零开始的索引。

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

搜索与指定谓词所定义的条件相匹配的元素,并返回整个 Array 中最后一个匹配元素的从零开始的索引。

ForEach<T>(T[], Action<T>)

对指定数组的每个元素执行指定操作。

GetEnumerator()

返回 IEnumeratorArray

GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetLength(Int32)

获取一个 32 位整数,该整数表示 Array 的指定维中的元素数。

GetLongLength(Int32)

获取一个 64 位整数,该整数表示 Array 的指定维中的元素数。

GetLowerBound(Int32)

获取数组中指定维度第一个元素的索引。

GetType()

获取当前实例的 Type

(继承自 Object)
GetUpperBound(Int32)

获取数组中指定维度最后一个元素的索引。

GetValue(Int32)

获取一维 Array 中指定位置的值。 索引指定为 32 位整数。

GetValue(Int32, Int32)

获取二维 Array 中指定位置的值。 索引指定为 32 位整数。

GetValue(Int32, Int32, Int32)

获取三维 Array 中指定位置的值。 索引指定为 32 位整数。

GetValue(Int32[])

获取多维 Array 中指定位置的值。 索引指定为一个 32 位整数数组。

GetValue(Int64)

获取一维 Array 中指定位置的值。 索引指定为 64 位整数。

GetValue(Int64, Int64)

获取二维 Array 中指定位置的值。 索引指定为 64 位整数。

GetValue(Int64, Int64, Int64)

获取三维 Array 中指定位置的值。 索引指定为 64 位整数。

GetValue(Int64[])

获取多维 Array 中指定位置的值。 索引指定为一个 64 位整数数组。

IndexOf(Array, Object)

在一个一维数组中搜索指定对象,并返回其首个匹配项的索引。

IndexOf(Array, Object, Int32)

在一个一维数组的一系列元素中搜索指定对象,然后返回其首个匹配项的索引。 范围从指定索引到该数组结尾。

IndexOf(Array, Object, Int32, Int32)

在一个一维数组的一系列元素中搜索指定对象,然后返回其首个匹配项的索引。 该元素系列的范围从指定数量的元素的指定索引开始。

IndexOf<T>(T[], T)

在一个一维数组中搜索指定对象,并返回其首个匹配项的索引。

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

在一个一维数组的一系列元素中搜索指定对象,然后返回其首个匹配项的索引。 范围从指定索引到该数组结尾。

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

在一个一维数组的一系列元素中搜索指定对象,然后返回其首个匹配项的索引。 该元素系列的范围从指定数量的元素的指定索引开始。

Initialize()

通过调用值类型的无参数构造函数,初始化值类型 Array 的每一个元素。

LastIndexOf(Array, Object)

在整个一维 Array 中搜索指定的对象,并返回最后一个匹配项的索引。

LastIndexOf(Array, Object, Int32)

搜索指定的对象,并返回一维 Array 中从第一个元素到指定索引的元素范围内最后一个匹配项的索引。

LastIndexOf(Array, Object, Int32, Int32)

搜索指定的对象并返回一维 Array 中包含指定数目元素且在指定索引处结尾的元素范围内的最后一个匹配项的索引。

LastIndexOf<T>(T[], T)

搜索指定的对象,并返回整个 Array 中最后一个匹配项的索引。

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

搜索指定的对象并返回 Array 中从第一个元素到指定索引的元素范围内最后一个匹配项的索引。

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

搜索指定的对象,并返回 Array 中包含指定数目元素并在指定索引处结尾的元素范围内的最后一个匹配项的索引。

MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
Resize<T>(T[], Int32)

将一维数组的元素数更改为指定的新大小。

Reverse(Array)

反转整个一维 Array 中元素的顺序。

Reverse(Array, Int32, Int32)

反转一维 Array 中元素子集的顺序。

Reverse<T>(T[])

反转一维泛型数组中元素的顺序。

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

反转一维泛型数组中元素子集的顺序。

SetValue(Object, Int32)

将值设置为一维 Array 中指定位置的元素。 索引指定为 32 位整数。

SetValue(Object, Int32, Int32)

将某值设置给二维 Array 中指定位置的元素。 索引指定为 32 位整数。

SetValue(Object, Int32, Int32, Int32)

将值设置为三维 Array 中指定位置的元素。 索引指定为 32 位整数。

SetValue(Object, Int32[])

将值设置为多维 Array 中指定位置的元素。 索引指定为一个 32 位整数数组。

SetValue(Object, Int64)

将值设置为一维 Array 中指定位置的元素。 索引指定为 64 位整数。

SetValue(Object, Int64, Int64)

将某值设置给二维 Array 中指定位置的元素。 索引指定为 64 位整数。

SetValue(Object, Int64, Int64, Int64)

将值设置为三维 Array 中指定位置的元素。 索引指定为 64 位整数。

SetValue(Object, Int64[])

将值设置为多维 Array 中指定位置的元素。 索引指定为一个 64 位整数数组。

Sort(Array)

使用 Array 中每个元素的 IComparable 实现,对整个一维 Array 中的元素进行排序。

Sort(Array, Array)

基于第一个 Array 中的关键字,使用每个关键字的 IComparable 实现,对两个一维 Array 对象(一个包含关键字,另一个包含对应的项)进行排序。

Sort(Array, Array, IComparer)

基于第一个 Array 中的关键字,使用指定的 IComparer,对两个一维 Array 对象(一个包含关键字,另一个包含对应的项)进行排序。

Sort(Array, Array, Int32, Int32)

基于第一个 Array 中的关键字,使用每个关键字的 IComparable 实现,对两个一维 Array 对象(一个包含关键字,另一个包含对应的项)的部分元素进行排序。

Sort(Array, Array, Int32, Int32, IComparer)

基于第一个 Array 中的关键字,使用指定的 IComparer,对两个一维 Array 对象(一个包含关键字,另一个包含对应的项)的部分元素进行排序。

Sort(Array, IComparer)

使用指定的 IComparer,对一维 Array 中的元素进行排序。

Sort(Array, Int32, Int32)

使用 Array 中每个元素的 IComparable 实现,对一维 Array 中的部分元素进行排序。

Sort(Array, Int32, Int32, IComparer)

使用指定的 IComparer,对一维 Array 中的部分元素进行排序。

Sort<T>(T[])

使用 Array 中每个元素的 IComparable<T> 泛型接口实现,对整个 Array 中的元素进行排序。

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

使用指定的 Comparison<T>,对 Array 中的元素进行排序。

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

使用指定的 IComparer<T> 泛型接口,对 Array 中的元素进行排序。

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

使用 Array 中每个元素的 IComparable<T> 泛型接口实现,对 Array 中元素范围内的元素进行排序。

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

使用指定的 IComparer<T> 泛型接口,对 Array 中的部分元素进行排序。

Sort<TKey,TValue>(TKey[], TValue[])

基于第一个 Array 中的键,使用每个键的 IComparable<T> 泛型接口实现,对一对 Array 对象(一个包含键,另一个包含对应的项)进行排序。

Sort<TKey,TValue>(TKey[], TValue[], IComparer<TKey>)

基于第一个 Array 中的关键字,使用指定的 IComparer<T> 泛型接口,对两个 Array 对象(一个包含关键字,另一个包含对应的项)进行排序。

Sort<TKey,TValue>(TKey[], TValue[], Int32, Int32)

基于第一个 Array 中的键,使用每个键的 IComparable<T> 泛型接口实现,对两个 Array 对象(一个包含键,另一个包含对应的项)的部分元素进行排序。

Sort<TKey,TValue>(TKey[], TValue[], Int32, Int32, IComparer<TKey>)

基于第一个 Array 中的关键字,使用指定的 IComparer<T> 泛型接口,对两个 Array 对象(一个包含关键字,另一个包含对应的项)的部分元素进行排序。

ToString()

返回表示当前对象的字符串。

(继承自 Object)
TrueForAll<T>(T[], Predicate<T>)

确定数组中的每个元素是否都与指定谓词定义的条件匹配。

显式接口实现

ICollection.Count

获取 Array 中包含的元素数。

ICollection.IsSynchronized

获取一个值,该值指示是否同步对 Array 的访问(线程安全)。

ICollection.SyncRoot

获取可用于同步对 Array 的访问的对象。

IList.Add(Object)

调用此方法始终会引发 NotSupportedException 异常。

IList.Clear()

IList 中移除所有项。

IList.Contains(Object)

确定某元素是否在 IList 中。

IList.IndexOf(Object)

确定 IList 中特定项的索引。

IList.Insert(Int32, Object)

IList 中的指定索引处插入一个项。

IList.IsFixedSize

获取一个值,该值指示 Array 是否具有固定大小。

IList.IsReadOnly

获取一个值,该值指示 Array 是否为只读。

IList.Item[Int32]

获取或设置指定索引处的元素。

IList.Remove(Object)

IList 中移除特定对象的第一个匹配项。

IList.RemoveAt(Int32)

移除位于指定索引处的 IList 项。

IStructuralComparable.CompareTo(Object, IComparer)

确定当前集合对象在排序顺序中的位置是位于另一个对象之前、之后还是与其位置相同。

IStructuralEquatable.Equals(Object, IEqualityComparer)

确定某个对象与当前实例是否相等。

IStructuralEquatable.GetHashCode(IEqualityComparer)

返回当前实例的哈希代码。

扩展方法

Cast<TResult>(IEnumerable)

IEnumerable 的元素强制转换为指定的类型。

OfType<TResult>(IEnumerable)

根据指定类型筛选 IEnumerable 的元素。

AsParallel(IEnumerable)

启用查询的并行化。

AsQueryable(IEnumerable)

IEnumerable 转换为 IQueryable

适用于

线程安全性

Visual Basic 中的公共静态 (Shared) 此类型的成员是线程安全的。 但不保证所有实例成员都是线程安全的。

此实现不会为 Array提供同步 (线程安全的) 包装器;但是,基于 Array .NET 类使用 SyncRoot 属性提供其自己的集合同步版本。

枚举整个集合本质上不是一个线程安全的过程。 即使某个集合已同步,其他线程仍可以修改该集合,这会导致枚举数引发异常。 若要确保枚举过程中的线程安全性,可以在整个枚举期间锁定集合,或者捕获由其他线程进行的更改所导致的异常。

另请参阅