C# Collection Clear
Description
removes all elements from the Collection.
Syntax
Collection.Clear
has the following syntax.
public void Clear()
Returns
Collection.Clear
method returns
Example
Removes all elements from the Collection.
using System;/* w ww.j ava 2s.co m*/
using System.Collections.Generic;
using System.Collections.ObjectModel;
public class Demo
{
public static void Main()
{
Collection<string> myData = new Collection<string>();
myData.Add("A");
myData.Add("B");
myData.Add("C");
myData.Add("D");
Console.WriteLine("{0} myData:", myData.Count);
myData.Clear();
Console.WriteLine("Count: {0}", myData.Count);
}
}
The code above generates the following result.