ArraySegment<T>.IList<T>.Item[Int32] ArraySegment<T>.IList<T>.Item[Int32] ArraySegment<T>.IList<T>.Item[Int32] Property

定义

获取或设置指定索引处的元素。Gets or sets the element at the specified index.

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; }
 Property Item(index As Integer) As T Implements IList(Of T).Item

参数

index
Int32 Int32 Int32

要获取或设置的元素的从零开始的索引。The zero-based index of the element to get or set.

属性值

T T T

指定索引处的元素。The element at the specified index.

实现

异常

index 不是 ArraySegment<T> 中的有效索引。index is not a valid index in the ArraySegment<T>.

设置该属性,而且数组段为只读。The property is set and the array segment is read-only.

注解

此成员是显式接口成员的实现。This member is an explicit interface member implementation. 它只能在ArraySegment<T>实例被强制转换IList<T>为接口时使用,如下例所示。It can be used only when the ArraySegment<T> instance is cast to an IList<T> interface, as the following example shows.

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

适用于