Add value to Generic List and display the array list using array indexing : Generic List « Generic « C# / CSharp Tutorial






using System;  
using System.Collections.Generic;  
  
class MainClass {  
  public static void Main() {  
    List<char> lst = new List<char>();  
      
    Console.WriteLine("Initial number of elements: " +  
                       lst.Count);  
  
    Console.WriteLine();  
  
    Console.WriteLine("Adding 6 elements");  

    lst.Add('C');  
    lst.Add('A');  
    lst.Add('E');  
    lst.Add('B');  
    lst.Add('D');  
    lst.Add('F');  
  
    Console.WriteLine("Number of elements: " +  
                       lst.Count);  
  
    Console.Write("Current contents: ");  
    for(int i=0; i < lst.Count; i++)  
      Console.Write(lst[i] + " ");  
    Console.WriteLine("\n");  
  }
}
Initial number of elements: 0

Adding 6 elements
Number of elements: 6
Current contents: C A E B D F








18.2.Generic List
18.2.1.Use generic list to store your own class
18.2.2.Create Reverse Iterator
18.2.3.Add value to Generic List and display the array list using array indexing
18.2.4.Remove elements from generic List
18.2.5.Use foreach loop to display the generic list
18.2.6.List Capacity and Element Count
18.2.7.Change contents in a generic List using array indexing
18.2.8.Store user-defined Objects in a List collection