C# List Item

Description

List Item gets or sets the element at the specified index.

Syntax

List.Item has the following syntax.


public T this[
  int index
] { get; set; }

Parameters

List.Item has the following parameters.

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

Example


/*from  www.j a v a2  s  .  c  o  m*/
using System;
using System.Collections.Generic;
public class MainClass{
  public static void Main(String[] argv){  
    List<string> myData = new List<string>();
    
    Console.WriteLine(myData.Capacity);
    
    myData.Add("A");
    myData.Add("B");
    myData.Add("C");
    myData.Add("D");
    myData.Add("E");
    
    Console.WriteLine(myData[3]);

  }
}
    

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Collections.Generic »




HashSet
LinkedList
LinkedListNode
List
Queue
SortedSet
Stack