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

Definition

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

Parameters

index
Int32 Int32 Int32

The zero-based index of the element to get or set.

Property Value

T T T

The element at the specified index.

Implements

Exceptions

The property is set and the array segment is read-only.

Remarks

This member is an explicit interface member implementation. 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

Applies to