ArraySegment<T> 結構

定義

分隔一維陣列的區段。Delimits a section of a one-dimensional array.

generic <typename T>
public value class ArraySegment : System::Collections::Generic::ICollection<T>, System::Collections::Generic::IEnumerable<T>, System::Collections::Generic::IList<T>, System::Collections::Generic::IReadOnlyCollection<T>, System::Collections::Generic::IReadOnlyList<T>
[System.Serializable]
public struct ArraySegment<T> : System.Collections.Generic.ICollection<T>, System.Collections.Generic.IEnumerable<T>, System.Collections.Generic.IList<T>, System.Collections.Generic.IReadOnlyCollection<T>, System.Collections.Generic.IReadOnlyList<T>
type ArraySegment<'T> = struct
    interface IList<'T>
    interface IReadOnlyList<'T>
    interface ICollection<'T>
    interface seq<'T>
    interface IEnumerable
    interface IReadOnlyCollection<'T>
Public Structure ArraySegment(Of T)
Implements ICollection(Of T), IEnumerable(Of T), IList(Of T), IReadOnlyCollection(Of T), IReadOnlyList(Of T)

類型參數

T

陣列區段中的項目類型。The type of the elements in the array segment.

繼承
ArraySegment<T>
屬性
實作

範例

下列程式碼範例會將 ArraySegment<T> 結構傳遞給方法。The following code example passes an ArraySegment<T> structure to a method.

using namespace System;


namespace Sample
{
    public ref class SampleArray  
    {
    public:
        static void Work()  
        {

            // Create and initialize a new string array.
            array <String^>^ words = {"The", "quick", "brown",
                "fox", "jumps", "over", "the", "lazy", "dog"};

            // Display the initial contents of the array.
            Console::WriteLine("The first array segment"
                " (with all the array's elements) contains:");
            PrintIndexAndValues(words);

            // Define an array segment that contains the entire array.
            ArraySegment<String^> segment(words);
            
            // Display the contents of the ArraySegment.
            Console::WriteLine("The first array segment"
                " (with all the array's elements) contains:");
            PrintIndexAndValues(segment);

            // Define an array segment that contains the middle five 
            // values of the array.
            ArraySegment<String^> middle(words, 2, 5);
            
            // Display the contents of the ArraySegment.
            Console::WriteLine("The second array segment"
                " (with the middle five elements) contains:");
            PrintIndexAndValues(middle);

            // Modify the fourth element of the first array 
            // segment
            segment.Array[3] = "LION";

            // Display the contents of the second array segment 
            // middle. Note that the value of its second element 
            // also changed.
            Console::WriteLine("After the first array segment"
                " is modified,the second array segment"
                " now contains:");
            PrintIndexAndValues(middle);
            Console::ReadLine();
        }

        static void PrintIndexAndValues(ArraySegment<String^>^ segment)  
        {
            for (int i = segment->Offset; 
                i < (segment->Offset + segment->Count); i++)  
            {
                Console::WriteLine("   [{0}] : {1}", i,
                    segment->Array[i]);
            }
            Console::WriteLine();
        }

        static void PrintIndexAndValues(array<String^>^ words) 
        {
            for (int i = 0; i < words->Length; i++)  
            {
                Console::WriteLine("   [{0}] : {1}", i,
                    words[i]);
            }
            Console::WriteLine();
        }
    };
}

int main()
{
    Sample::SampleArray::Work();
    return 0; 
}


    /* 
    This code produces the following output.

    The original array initially contains:
    [0] : The
    [1] : quick
    [2] : brown
    [3] : fox
    [4] : jumps
    [5] : over
    [6] : the
    [7] : lazy
    [8] : dog

    The first array segment (with all the array's elements) contains:
    [0] : The
    [1] : quick
    [2] : brown
    [3] : fox
    [4] : jumps
    [5] : over
    [6] : the
    [7] : lazy
    [8] : dog

    The second array segment (with the middle five elements) contains:
    [2] : brown
    [3] : fox
    [4] : jumps
    [5] : over
    [6] : the

    After the first array segment is modified, the second array segment now contains:
    [2] : brown
    [3] : LION
    [4] : jumps
    [5] : over
    [6] : the

    */

using System;

public class SamplesArray  {
 
   public static void Main()  {
 
      // Create and initialize a new string array.
      String[] myArr = { "The", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog" };
 
      // Display the initial contents of the array.
      Console.WriteLine( "The original array initially contains:" );
      PrintIndexAndValues( myArr );

      // Define an array segment that contains the entire array.
      ArraySegment<String> myArrSegAll = new ArraySegment<String>( myArr );

      // Display the contents of the ArraySegment.
      Console.WriteLine( "The first array segment (with all the array's elements) contains:" );
      PrintIndexAndValues( myArrSegAll );

      // Define an array segment that contains the middle five values of the array.
      ArraySegment<String> myArrSegMid = new ArraySegment<String>( myArr, 2, 5 );

      // Display the contents of the ArraySegment.
      Console.WriteLine( "The second array segment (with the middle five elements) contains:" );
      PrintIndexAndValues( myArrSegMid );

      // Modify the fourth element of the first array segment myArrSegAll.
      myArrSegAll.Array[3] = "LION";

      // Display the contents of the second array segment myArrSegMid.
      // Note that the value of its second element also changed.
      Console.WriteLine( "After the first array segment is modified, the second array segment now contains:" );
      PrintIndexAndValues( myArrSegMid );

   }
 
   public static void PrintIndexAndValues( ArraySegment<String> arrSeg )  {
      for ( int i = arrSeg.Offset; i < (arrSeg.Offset + arrSeg.Count); i++ )  {
         Console.WriteLine( "   [{0}] : {1}", i, arrSeg.Array[i] );
      }
      Console.WriteLine();
   }

   public static void PrintIndexAndValues( String[] myArr )  {
      for ( int i = 0; i < myArr.Length; i++ )  {
         Console.WriteLine( "   [{0}] : {1}", i, myArr[i] );
      }
      Console.WriteLine();
   }

}


/* 
This code produces the following output.

The original array initially contains:
   [0] : The
   [1] : quick
   [2] : brown
   [3] : fox
   [4] : jumps
   [5] : over
   [6] : the
   [7] : lazy
   [8] : dog

The first array segment (with all the array's elements) contains:
   [0] : The
   [1] : quick
   [2] : brown
   [3] : fox
   [4] : jumps
   [5] : over
   [6] : the
   [7] : lazy
   [8] : dog

The second array segment (with the middle five elements) contains:
   [2] : brown
   [3] : fox
   [4] : jumps
   [5] : over
   [6] : the

After the first array segment is modified, the second array segment now contains:
   [2] : brown
   [3] : LION
   [4] : jumps
   [5] : over
   [6] : the

*/

Public Class SamplesArray

    Public Shared Sub Main()

        ' Create and initialize a new string array.
        Dim myArr As String() =  {"The", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"}

        ' Display the initial contents of the array.
        Console.WriteLine("The original array initially contains:")
        PrintIndexAndValues(myArr)

        ' Define an array segment that contains the entire array.
        Dim myArrSegAll As New ArraySegment(Of String)(myArr)

        ' Display the contents of the ArraySegment.
        Console.WriteLine("The first array segment (with all the array's elements) contains:")
        PrintIndexAndValues(myArrSegAll)

        ' Define an array segment that contains the middle five values of the array.
        Dim myArrSegMid As New ArraySegment(Of String)(myArr, 2, 5)

        ' Display the contents of the ArraySegment.
        Console.WriteLine("The second array segment (with the middle five elements) contains:")
        PrintIndexAndValues(myArrSegMid)

        ' Modify the fourth element of the first array segment myArrSegAll.
        myArrSegAll.Array(3) = "LION"

        ' Display the contents of the second array segment myArrSegMid.
        ' Note that the value of its second element also changed.
        Console.WriteLine("After the first array segment is modified, the second array segment now contains:")
        PrintIndexAndValues(myArrSegMid)

    End Sub

    Public Shared Sub PrintIndexAndValues(arrSeg As ArraySegment(Of String))
        Dim i As Integer
        For i = arrSeg.Offset To (arrSeg.Offset + arrSeg.Count - 1)
            Console.WriteLine("   [{0}] : {1}", i, arrSeg.Array(i))
        Next i
        Console.WriteLine()
    End Sub

    Public Shared Sub PrintIndexAndValues(myArr as String())
        Dim i As Integer
        For i = 0 To (myArr.Length - 1)
            Console.WriteLine("   [{0}] : {1}", i, myArr(i))
        Next i
        Console.WriteLine()
    End Sub

End Class


'This code produces the following output.
'
'The original array initially contains:
'   [0] : The
'   [1] : quick
'   [2] : brown
'   [3] : fox
'   [4] : jumps
'   [5] : over
'   [6] : the
'   [7] : lazy
'   [8] : dog
'
'The first array segment (with all the array's elements) contains:
'   [0] : The
'   [1] : quick
'   [2] : brown
'   [3] : fox
'   [4] : jumps
'   [5] : over
'   [6] : the
'   [7] : lazy
'   [8] : dog
'
'The second array segment (with the middle five elements) contains:
'   [2] : brown
'   [3] : fox
'   [4] : jumps
'   [5] : over
'   [6] : the
'
'After the first array segment is modified, the second array segment now contains:
'   [2] : brown
'   [3] : LION
'   [4] : jumps
'   [5] : over
'   [6] : the

備註

ArraySegment<T> 是陣列的包裝函式,它會分隔該陣列中某個範圍的元素。ArraySegment<T> is a wrapper around an array that delimits a range of elements in that array. 多個 ArraySegment<T> 實例可以參考相同的原始陣列,而且可以重迭。Multiple ArraySegment<T> instances can refer to the same original array and can overlap. 原始陣列必須是一維,而且必須具有以零為起始的索引。The original array must be one-dimensional and must have zero-based indexing.

注意

ArraySegment<T> 會執行從 .NET Framework 4.6.NET Framework 4.6 開始的 IReadOnlyCollection<T> 介面;在舊版的 .NET Framework 中,ArraySegment<T> 結構並未執行此介面。ArraySegment<T> implements the IReadOnlyCollection<T> interface starting with the .NET Framework 4.6.NET Framework 4.6; in previous versions of the .NET Framework, the ArraySegment<T> structure did not implement this interface.

每當陣列的元素會在不同的區段中操作時,ArraySegment<T> 結構就很有用。The ArraySegment<T> structure is useful whenever the elements of an array will be manipulated in distinct segments. 例如:For example:

  • 您可以將只代表陣列一部分的 ArraySegment<T> 物件當做引數傳遞至方法,而不是呼叫相當昂貴的方法(例如 Copy)來傳遞陣列部分的複本。You can pass an ArraySegment<T> object that represents only a portion of an array as an argument to a method, rather than call a relatively expensive method like Copy to pass a copy of a portion of an array.

  • 在多執行緒應用程式中,您可以使用 ArraySegment<T> 結構,讓每個執行緒只能在陣列的一部分上運作。In a multithreaded app, you can use the ArraySegment<T> structure to have each thread operate on only a portion of the array.

  • 針對以工作為基礎的非同步作業,您可以使用 ArraySegment<T> 物件,以確保每個工作都是在陣列的不同區段上操作。For task-based asynchronous operations, you can use an ArraySegment<T> object to ensure that each task operates on a distinct segment of the array. 下列範例會將陣列分割成包含最多10個元素的個別區段。The following example divides an array into individual segments with up to ten elements. 區段中的每個元素會乘以其區段編號。Each element in the segment is multiplied by its segment number. 結果顯示,使用 ArraySegment<T> 類別以這種方式操作元素,會變更其基礎陣列的值。The result shows that using the ArraySegment<T> class to manipulate elements in this way changes the values of its underlying array.

    using System;
    using System.Collections.Generic;
    using System.Threading.Tasks;
    
    public class Example
    {
       private const int segmentSize = 10;
       
       public static async Task Main()
       {
          List<Task> tasks = new List<Task>();
    
          // Create array.
          int[] arr = new int[50];
          for (int ctr = 0; ctr <= arr.GetUpperBound(0); ctr++)
             arr[ctr] = ctr + 1;
    
          // Handle array in segments of 10.
          for (int ctr = 1; ctr <= Math.Ceiling(((double)arr.Length)/segmentSize); ctr++) {
             int multiplier = ctr;
             int elements = (multiplier - 1) * 10 + segmentSize > arr.Length ?
                             arr.Length - (multiplier - 1) * 10 : segmentSize;
             ArraySegment<int> segment = new ArraySegment<int>(arr, (ctr - 1) * 10, elements);
             tasks.Add(Task.Run( () => { IList<int> list = (IList<int>) segment;
                                         for (int index = 0; index < list.Count; index++)
                                            list[index] = list[index] * multiplier;
                                       } ));
          }
          try {
             await Task.WhenAll(tasks.ToArray());
             int elementsShown = 0;
             foreach (var value in arr) {
                Console.Write("{0,3} ", value);
                elementsShown++;
                if (elementsShown % 18 == 0)
                   Console.WriteLine();
             }
          }
          catch (AggregateException e) {
             Console.WriteLine("Errors occurred when working with the array:");
             foreach (var inner in e.InnerExceptions)
                Console.WriteLine("{0}: {1}", inner.GetType().Name, inner.Message);
          }
       }
    }
    // The example displays the following output:
    //      1   2   3   4   5   6   7   8   9  10  22  24  26  28  30  32  34  36
    //     38  40  63  66  69  72  75  78  81  84  87  90 124 128 132 136 140 144
    //    148 152 156 160 205 210 215 220 225 230 235 240 245 250
    
    Imports System.Collections.Generic
    Imports System.Threading.Tasks
    
    Module Example
      Private Const SegmentSize As Integer = 10
      
       Public Sub Main()
          Dim tasks As New List(Of Task)
          
           ' Create array.
          Dim arr(49) As Integer
          For ctr As Integer = 0 To arr.GetUpperBound(0)
             arr(ctr) = ctr + 1
          Next
    
          ' Handle array in segments of 10.
          For ctr As Integer = 1 To CInt(Math.Ceiling(arr.Length / segmentSize))
             Dim multiplier As Integer = ctr
             Dim elements As Integer = If((multiplier - 1) * 10 + segmentSize > arr.Length,
                                          arr.Length - (multiplier - 1) * 10,
                                          segmentSize)
             Dim segment As New ArraySegment(Of Integer)(arr, (ctr - 1) * 10, elements)
             tasks.Add(Task.Run( Sub()
                                    Dim list As IList(Of Integer) = CType(segment, IList(Of Integer))
                                    For index As Integer = 0 To list.Count - 1
                                       list(index) = list(index) * multiplier
                                    Next
                                 End Sub ))
          Next
          Try
             Task.WaitAll(tasks.ToArray())
             Dim elementsShown As Integer = 0
             For Each value In arr
                Console.Write("{0,3} ", value)
                elementsShown += 1
                If elementsShown Mod 18 = 0 Then Console.WriteLine()
             Next
          Catch e As AggregateException
             Console.WriteLine("Errors occurred when working with the array:")
             For Each inner As Exception In e.InnerExceptions
                Console.WriteLine("{0}: {1}", inner.GetType().Name, inner.Message)
             Next
          End Try
       End Sub
    End Module
    ' The example displays the following output:
    '         1   2   3   4   5   6   7   8   9  10  22  24  26  28  30  32  34  36
    '        38  40  63  66  69  72  75  78  81  84  87  90 124 128 132 136 140 144
    '       148 152 156 160 205 210 215 220 225 230 235 240 245 250
    

不過要注意的是,雖然 ArraySegment<T> 結構可用來將陣列分割成不同的區段,但區段並不完全獨立。Note, however, that although the ArraySegment<T> structure can be used to divide an array into distinct segments, the segments are not completely independent of one another. Array 屬性會傳回整個原始陣列,而不是陣列的複本;因此,對原始陣列進行 Array 屬性所傳回之陣列的變更。The Array property returns the entire original array, not a copy of the array; therefore, changes made to the array returned by the Array property are made to the original array. 如果不想要這樣做,您應該在陣列的複本上執行作業,而不是代表陣列一部分的 ArraySegment<T> 物件。If this is undesirable, you should perform operations on a copy of the array, rather than an ArraySegment<T> object that represents a portion of the array.

Equals 方法和相等和不等比較運算子會在比較兩個 ArraySegment<T> 的物件時,測試參考是否相等。The Equals method and the equality and inequality operators test for reference equality when they compare two ArraySegment<T> objects. 若要將兩個 ArraySegment<T> 的物件視為相等,它們必須符合下列所有條件:For two ArraySegment<T> objects to be considered equal, they must meet all of the following conditions:

  • 參考相同的陣列。Reference the same array.

  • 從陣列中的相同索引開始。Begin at the same index in the array.

  • 具有相同數目的元素。Have the same number of elements.

如果您想要依其在 ArraySegment<T> 物件中的索引來抓取專案,您必須將它轉換成 IList<T> 物件,並使用 IList<T>.Item[Int32] 屬性來加以取出或修改。If you want to retrieve an element by its index in the ArraySegment<T> object, you must cast it to an IList<T> object and retrieve it or modify it by using the IList<T>.Item[Int32] property. 下列範例會抓取 ArraySegment<T> 物件中的專案,該專案會分隔字串陣列的區段。The following example retrieves the element in an ArraySegment<T> object that delimits a section of a string array.

using System;
using System.Collections.Generic;

public class Example
{
   public static void Main()
   {
      String[] names = { "Adam", "Bruce", "Charles", "Daniel", 
                         "Ebenezer", "Francis", "Gilbert", 
                         "Henry", "Irving", "John", "Karl",
                         "Lucian", "Michael" };
      var partNames = new ArraySegment<String>(names, 2, 5);
      
      // Cast the ArraySegment object to an IList<String> and enumerate it.
      var list = (IList<String>) partNames;
      for (int ctr = 0; ctr <= list.Count - 1; ctr++)
         Console.WriteLine(list[ctr]);
   }
}
// The example displays the following output:
//    Charles
//    Daniel
//    Ebenezer
//    Francis
//    Gilbert
Imports System.Collections.Generic

Module Example
   Public Sub Main()
      Dim names() As String = { "Adam", "Bruce", "Charles", "Daniel", 
                                "Ebenezer", "Francis", "Gilbert", 
                                "Henry", "Irving", "John", "Karl",
                                "Lucian", "Michael" }
      Dim partNames As New ArraySegment(Of String)(names, 2, 5)
      
      ' Cast the ArraySegment object to an IList<String> and enumerate it.
      Dim list = CType(partNames, IList(Of String))
      For ctr As Integer = 0 To list.Count - 1
         Console.WriteLine(list(ctr))
      Next     
   End Sub
End Module
' The example displays the following output:
'    Charles
'    Daniel
'    Ebenezer
'    Francis
'    Gilbert

建構函式

ArraySegment<T>(T[])

初始化 ArraySegment<T> 結構的新執行個體,這個新執行個體會分隔指定陣列中的所有項目。Initializes a new instance of the ArraySegment<T> structure that delimits all the elements in the specified array.

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

初始化 ArraySegment<T> 結構的新執行個體,這個新執行個體會分隔指定陣列中的指定項目範圍。Initializes a new instance of the ArraySegment<T> structure that delimits the specified range of the elements in the specified array.

屬性

Array

取得原始陣列,這個陣列包含陣列區段分隔的項目範圍。Gets the original array containing the range of elements that the array segment delimits.

Count

取得陣列區段分隔範圍中的項目數目。Gets the number of elements in the range delimited by the array segment.

Empty
Item[Int32]

在指定的索引位置上取得或設定項目。Gets or sets the element at the specified index.

Offset

取得陣列區段分隔範圍中的第一個項目位置,相對於原始陣列的開頭。Gets the position of the first element in the range delimited by the array segment, relative to the start of the original array.

方法

CopyTo(ArraySegment<T>)
CopyTo(T[])
CopyTo(T[], Int32)
Equals(ArraySegment<T>)

判斷指定的 ArraySegment<T> 結構和目前的執行個體是否相等。Determines whether the specified ArraySegment<T> structure is equal to the current instance.

Equals(Object)

判斷指定的物件是否和目前的執行個體相等。Determines whether the specified object is equal to the current instance.

GetEnumerator()

傳回可用來逐一查看陣列區段的列舉程式。Returns an enumerator that can be used to iterate through the array segment.

GetHashCode()

傳回目前執行個體的雜湊碼。Returns the hash code for the current instance.

Slice(Int32)
Slice(Int32, Int32)
ToArray()

將此陣列區段的內容複製到新陣列。Copies the contents of this array segment into a new array.

運算子

Equality(ArraySegment<T>, ArraySegment<T>)

指出兩個 ArraySegment<T> 結構是否相等。Indicates whether two ArraySegment<T> structures are equal.

Implicit(T[] to ArraySegment<T>)
Inequality(ArraySegment<T>, ArraySegment<T>)

指出兩個 ArraySegment<T> 結構是否不相等。Indicates whether two ArraySegment<T> structures are unequal.

明確介面實作

ICollection<T>.Add(T)

在所有情況下都會擲回 NotSupportedException 例外狀況。Throws a NotSupportedException exception in all cases.

ICollection<T>.Clear()

在所有情況下都會擲回 NotSupportedException 例外狀況。Throws a NotSupportedException exception in all cases.

ICollection<T>.Contains(T)

判斷此陣列區段是否包含特定的值。Determines whether the array segment contains a specific value.

ICollection<T>.CopyTo(T[], Int32)

從指定的陣列索引處開始,將陣列區段的項目複製到陣列。Copies the elements of the array segment to an array, starting at the specified array index.

ICollection<T>.IsReadOnly

取得值,指出陣列區段是否為唯讀。Gets a value that indicates whether the array segment is read-only.

ICollection<T>.Remove(T)

在所有情況下都會擲回 NotSupportedException 例外狀況。Throws a NotSupportedException exception in all cases.

IEnumerable.GetEnumerator()

傳回列舉值,該值可逐一查看陣列區段。Returns an enumerator that iterates through an array segment.

IEnumerable<T>.GetEnumerator()

傳回列舉值,該值可逐一查看陣列區段。Returns an enumerator that iterates through the array segment.

IList<T>.IndexOf(T)

判斷陣列區段中特定項目的索引。Determines the index of a specific item in the array segment.

IList<T>.Insert(Int32, T)

在所有情況下都會擲回 NotSupportedException 例外狀況。Throws a NotSupportedException exception in all cases.

IList<T>.Item[Int32]

在指定的索引位置上取得或設定項目。Gets or sets the element at the specified index.

IList<T>.RemoveAt(Int32)

在所有情況下都會擲回 NotSupportedException 例外狀況。Throws a NotSupportedException exception in all cases.

IReadOnlyList<T>.Item[Int32]

取得位於陣列區段之指定索引位置的項目。Gets the element at the specified index of the array segment.

擴充方法

CopyToDataTable<T>(IEnumerable<T>)

根據輸入 DataTable 物件 (其中泛型參數 TDataRow) 傳回包含 IEnumerable<T> 物件複本的 DataRowReturns a DataTable that contains copies of the DataRow objects, given an input IEnumerable<T> object where the generic parameter T is DataRow.

CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption)

根據輸入 DataRow 物件 (其中泛型參數 TDataTable),將 IEnumerable<T> 物件複製到指定的 DataRowCopies DataRow objects to the specified DataTable, given an input IEnumerable<T> object where the generic parameter T is DataRow.

CopyToDataTable<T>(IEnumerable<T>, DataTable, LoadOption, FillErrorEventHandler)

根據輸入 DataRow 物件 (其中泛型參數 TDataTable),將 IEnumerable<T> 物件複製到指定的 DataRowCopies DataRow objects to the specified DataTable, given an input IEnumerable<T> object where the generic parameter T is DataRow.

Cast<TResult>(IEnumerable)

IEnumerable 的項目轉換成指定的型別。Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable)

根據指定的型別來篩選 IEnumerable 的項目。Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable)

啟用查詢的平行化作業。Enables parallelization of a query.

AsQueryable(IEnumerable)

IEnumerable 轉換成 IQueryableConverts an IEnumerable to an IQueryable.

AsMemory<T>(ArraySegment<T>)

在目標陣列區段部分上建立新記憶體區域。Creates a new memory region over the portion of the target array segment.

AsMemory<T>(ArraySegment<T>, Int32)

在起始於指定位置到區段結尾的目標陣列區段部分上建立新記憶體區域。Creates a new memory region over the portion of the target array segment starting at a specified position to the end of the segment.

AsMemory<T>(ArraySegment<T>, Int32, Int32)

在起始於指定位置且具有指定長度的目標陣列區段部分上建立新記憶體區域。Creates a new memory region over the portion of the target array segment beginning at a specified position with a specified length.

AsSpan<T>(ArraySegment<T>)

在目標陣列區段上建立新範圍。Creates a new span over a target array segment.

AsSpan<T>(ArraySegment<T>, Index)

在起始於指定索引且結束於區段結尾的目標陣列區段部分上建立新範圍。Creates a new span over a portion of the target array segment beginning at a specified index and ending at the end of the segment.

AsSpan<T>(ArraySegment<T>, Int32)

在起始於指定位置到區段結尾的目標陣列區段部分上建立新範圍。Creates a new span over a portion of a target array segment from a specified position to the end of the segment.

AsSpan<T>(ArraySegment<T>, Int32, Int32)

在起始於指定位置且具有指定長度的目標陣列區段部分上建立新範圍。Creates a new span over a portion of a target array segment from a specified position for a specified length.

AsSpan<T>(ArraySegment<T>, Range)

在使用範圍開始和結束索引的目標陣列區段部分上建立新範圍。Creates a new span over a portion of a target array segment using the range start and end indexes.

Ancestors<T>(IEnumerable<T>)

傳回包含來源集合中每個節點祖系的項目集合。Returns a collection of elements that contains the ancestors of every node in the source collection.

Ancestors<T>(IEnumerable<T>, XName)

傳回包含來源集合中每個節點祖系的已篩選項目集合。Returns a filtered collection of elements that contains the ancestors of every node in the source collection. 集合中只會包含具有相符之 XName 的項目。Only elements that have a matching XName are included in the collection.

DescendantNodes<T>(IEnumerable<T>)

傳回來源集合中每個文件和項目之子代節點的集合。Returns a collection of the descendant nodes of every document and element in the source collection.

Descendants<T>(IEnumerable<T>)

傳回包含來源集合中每個項目和文件之子代項目的項目集合。Returns a collection of elements that contains the descendant elements of every element and document in the source collection.

Descendants<T>(IEnumerable<T>, XName)

傳回已篩選的項目集合,其中包含來源集合中每個項目和文件的子代項目。Returns a filtered collection of elements that contains the descendant elements of every element and document in the source collection. 集合中只會包含具有相符之 XName 的項目。Only elements that have a matching XName are included in the collection.

Elements<T>(IEnumerable<T>)

傳回來源集合中每個項目和文件的子項目集合。Returns a collection of the child elements of every element and document in the source collection.

Elements<T>(IEnumerable<T>, XName)

傳回來源集合中每個項目和文件的已篩選子項目集合。Returns a filtered collection of the child elements of every element and document in the source collection. 集合中只會包含具有相符之 XName 的項目。Only elements that have a matching XName are included in the collection.

InDocumentOrder<T>(IEnumerable<T>)

傳回包含來源集合中所有節點的節點集合,依據文件順序來排序。Returns a collection of nodes that contains all nodes in the source collection, sorted in document order.

Nodes<T>(IEnumerable<T>)

傳回來源集合中每個文件和項目的子節點集合。Returns a collection of the child nodes of every document and element in the source collection.

Remove<T>(IEnumerable<T>)

在來源集合中,從每一個節點的父節點移除這些節點。Removes every node in the source collection from its parent node.

適用於

另請參閱