Remove all elements from the Collection in CSharp

Description

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

Example


using System;/*  ww  w  .j av  a2  s .  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(myData.Count);
        myData.Clear();
        Console.WriteLine(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