Get or set the total number of elements the internal data structure can hold without resizing in CSharp

Description

The following code shows how to get or set the total number of elements the internal data structure can hold without resizing.

Example


using System;/*from   ww w  .j  av a 2  s  .  co  m*/
using System.Collections.Generic;

public class Example
{
    public static void Main()
    {
        List<string> letters = new List<string>();

        Console.WriteLine(letters.Capacity);

        letters.Add("A");
        letters.Add("B");
        letters.Add("C");
        letters.Add("D");
        letters.Add("E");

        Console.WriteLine(letters.Capacity);
        Console.WriteLine(letters.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