ArraySegment<T>.IList<T>.Item[Int32] 属性

定义

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

property T System::Collections::Generic::IList<T>::Item[int] { T get(int index); void set(int index, T value); };
T System.Collections.Generic.IList<T>.Item[int index] { get; set; }
member this.System.Collections.Generic.IList<T>.Item(int) : 'T with get, set
 Property Item(index As Integer) As T Implements IList(Of T).Item

参数

index
Int32

要获取或设置的元素的从零开始的索引。

属性值

T

指定索引处的元素。

实现

例外

index 不是 ArraySegment<T> 中的有效索引。

设置该属性,而且数组段为只读。

注解

此成员是显式接口成员的实现。 仅当实例强制转换为IList<T>接口时ArraySegment<T>,才能使用它,如以下示例所示。

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
open System

let names = 
    [| "Adam"; "Bruce"; "Charles"; "Daniel"
       "Ebenezer"; "Francis"; "Gilbert"
       "Henry"; "Irving"; "John"; "Karl"
       "Lucian"; "Michael" |]

let partNames = ArraySegment<string>(names, 2, 5)

// Enumerate over the ArraySegment object.
for part in partNames do 
    printfn $"{part}"

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

适用于