Sunday 11 May 2014

copies array to List: C#

using System;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
 int[] arr = new int[3]; // New array with 3 elements
 arr[0] = 2;
 arr[1] = 3;
 arr[2] = 5;
 List<int> list = new List<int>(arr); // Copy to List
 Console.WriteLine(list.Count);       // 3 elements in List
    }
}

Output
    (Indicates number of elements.)

3

No comments:

Post a Comment