Tuesday, March 10, 2015

C# List Add Method

Add places an element at the end of a List. It handles both value types and reference types. The Add instance method on the List type has internal logic that allows you to quickly add elements to the end of the collection.


using System.Collections.Generic;

class Program
{
    static void Main()
    {
 // Add first four numbers to the List.
 List<int> primes = new List<int>();
 primes.Add(2);
 primes.Add(3);
 primes.Add(5);
 primes.Add(7);
    }
}

No comments:

Post a Comment