C# List TrimExcess

Description

List TrimExcess sets the capacity to the actual number of elements in the List , if that number is less than a threshold value.

Syntax

List.TrimExcess has the following syntax.


public void TrimExcess()

Example


//  w w w  .ja  va  2 s . c o  m
using System;
using System.Collections.Generic;

public class Example
{
    public static void Main()
    {
        string[] input = { "A", "B", "C" };

        List<string> myData = new List<string>(input);
        string[] output = myData.GetRange(2, 3).ToArray();

        myData.TrimExcess();
        foreach( string myD in output )
        {
            Console.WriteLine(myD);
        }
    }
}




















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




HashSet
LinkedList
LinkedListNode
List
Queue
SortedSet
Stack