C# HashSet TrimExcess
Description
HashSet
sets the capacity of a HashSet
Syntax
HashSet.TrimExcess
has the following syntax.
public void TrimExcess()
Example
The following example creates and populates a HashSet collection, and then clears the collection and releases the memory referenced by it.
//ww w . ja v a2 s .c om
using System;
using System.Collections.Generic;
public class MainClass{
public static void Main(String[] argv){
HashSet<int> Numbers = new HashSet<int>();
for (int i = 0; i < 10; i++)
{
Numbers.Add(i);
}
Numbers.Clear();
Numbers.TrimExcess();
}
}