Remove all elements from the List in CSharp

Description

The following code shows how to remove all elements from the List.

Example


using System;//  w  w  w  . j a v  a  2s .c  o m
using System.Collections.Generic;

public class Example
{
    public static void Main()
    {
        List<string> myData = new List<string>();

        myData.Add("A");
        myData.Add("B");
        myData.Add("C");
        myData.Add("D");
        Console.WriteLine("Capacity:" + myData.Capacity);
        Console.WriteLine("Count" + myData.Count);

        myData.Clear();
        Console.WriteLine("Clear()");

        Console.WriteLine("Capacity:" + myData.Capacity);
        Console.WriteLine("Count" + myData.Count);
        
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Collections »




ArrayList
BitArray
Collection
Comparer
HashSet
Hashtable
LinkedList
List
ListDictionary
OrderedDictionary
Queue
SortedList
SortedSet
Stack
StringCollection
StringDictionary