C# List Clear
Description
List
removes all elements from the List
Syntax
List.Clear
has the following syntax.
public void Clear()
Example
The following example demonstrates the Clear method.
using System;/*from w ww . ja v a2 s . co 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("\nCapacity: {0}", myData.Capacity);
Console.WriteLine("Count: {0}", myData.Count);
myData.Clear();
Console.WriteLine("\nClear()");
Console.WriteLine("Capacity: {0}", myData.Capacity);
Console.WriteLine("Count: {0}", myData.Count);
}
}
The code above generates the following result.