C# List List(Int32)
Description
List
initializes a new instance
of the List
Syntax
public List(
int capacity
)
Parameters
capacity
- The number of elements that the new list can initially store.
Example
The following example demonstrates the List(Int32) constructor.
// w w w . j a v a 2 s.c om
using System;
using System.Collections.Generic;
public class Example
{
public static void Main()
{
List<string> myData = new List<string>(4);
Console.WriteLine("\nCapacity: {0}", myData.Capacity);
myData.Add("A");
myData.Add("B");
myData.Add("C");
myData.Add("D");
foreach(string s in myData)
{
Console.WriteLine(s);
}
}
}
The code above generates the following result.