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; }
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

Parameters

index
Int32

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

Property Value

T

The element at the specified index.

Implements

Exceptions

index is not a valid index in the ArraySegment<T>.

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

Applies to