ArraySegment<T>.IList<T>.Item[Int32] 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定位於指定索引處的專案。
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>。
屬性已設定,陣列區段為唯讀。
備註
此成員為明確介面成員實作。 它只能在實 ArraySegment<T> 例投射到 IList<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