C# HashSet TrimExcess

Description

HashSet TrimExcess sets the capacity of a HashSet object to the actual number of elements it contains, rounded up to a nearby, implementation-specific value.

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();
  }
}




















Home »
  C# Tutorial »
    System.Collections.Generic »




HashSet
LinkedList
LinkedListNode
List
Queue
SortedSet
Stack