Array 類別

定義

提供建立、管理、搜尋和排序陣列的方法,可在 Common Language Runtime 時做為所有陣列的基底類別。

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 億個元素,而且在任何指定的維度中,0X7FEFFFFF的最大索引, (0X7FFFFFC7位元組陣列和單一位元組結構的陣列) 。

僅限.NET Framework:根據預設,大小上限 Array 為 2 GB (GB) 。 在 64 位環境中,您可以在執行時間環境中將gcAllowVeryLargeObjects組態專案的 屬性設定 enabledtrue ,以避免大小限制。

單一維度陣列會實作 System.Collections.Generic.IList<T>System.Collections.Generic.ICollection<T>System.Collections.Generic.IEnumerable<T>System.Collections.Generic.IReadOnlyList<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 不僅會在相同類型的陣列之間複製元素,也會在不同類型的標準陣列之間複製專案;它會自動處理型別轉換。

某些方法,例如 CreateInstanceCopyCopyToGetValueSetValue ,會提供接受 64 位整數做為參數的多載,以容納大型容量陣列。 LongLength 和 會 GetLongLength 傳回指出陣列長度的 64 位整數。

Array不保證會排序 。 您必須在執行作業之前先排序 Array , (例如 BinarySearch 需要 Array 排序 的) 。

Array不支援在機器碼中使用指標的物件,而且會針對數個方法擲回 NotSupportedException

屬性

IsFixedSize

取得值,指出 Array 是否有固定的大小。

IsReadOnly

取得值,指出 Array 是否唯讀。

IsSynchronized

取得值,這個值表示對 Array 的存取是否同步 (安全執行緒)。

Length

取得 Array 所有維度的元素總數。

LongLength

取得代表 Array 所有維度的元素總數之 64 位元整數。

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>)

判斷指定的陣列是否包含符合指定之述詞 (Predicate) 所定義的條件之項目。

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)

取得代表 Array 指定維度之項目數目的 32 位元整數。

GetLongLength(Int32)

取得代表 Array 指定維度之元素數目的 64 位元整數。

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)

使用每個索引鍵的 IComparable 實作,根據第一個 Array 中的索引鍵,排序一對一維的 Array 物件 (一個物件包含索引鍵,另一個物件包含對應的項目)。

Sort(Array, Array, IComparer)

使用指定的 IComparer,根據第一個 Array 中的索引鍵,排序一對一維的 Array 物件 (一個物件包含索引鍵,另一個物件包含對應的項目)。

Sort(Array, Array, Int32, Int32)

使用每個索引鍵的 IComparable 實作,根據第一個 Array 中的索引鍵,排序一對一維的 Array 物件中某個範圍的項目 (一個物件包含索引鍵,另一個物件包含對應的項目)。

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

使用指定的 IComparer,根據第一個 Array 中的索引鍵,排序一對一維 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[])

使用每個索引鍵的 IComparable<T> 泛型介面實作,根據第一個 Array 中的索引鍵,排序一對 Array 物件 (一個物件包含索引鍵,另一個物件包含對應的項目)。

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

使用指定的 IComparer<T> 泛型介面,根據第一個 Array 中的索引鍵,排序一對 Array 物件 (一個物件包含索引鍵,另一個物件包含對應的項目)。

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

使用每個索引鍵的 IComparable<T> 泛型介面實作,根據第一個 Array 中的索引鍵,排序一對 Array 物件中某個範圍的項目 (一個物件包含索引鍵,另一個物件包含對應的項目)。

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

使用指定的 IComparer<T> 泛型介面,根據第一個 Array 中的索引鍵,排序一對 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 函式;不過,.NET 類別會使用 ArraySyncRoot 屬性提供自己的已同步處理集合版本。

透過集合進行列舉在本質上並非安全執行緒程序。 即使集合經過同步化,其他的執行緒仍可修改該集合,使列舉值擲回例外狀況。 若要保證列舉過程的執行緒安全,您可以在整個列舉過程中鎖定集合,或攔截由其他執行緒的變更所造成的例外狀況。

另請參閱