stuart-d2
4/22/2015 - 5:54 PM

List : Array to List

List : Array to List

//Array to List
/*

	• Creating a list with elements from an array.
	• Use the List constructor and pass it an array
	• List receives this parameter and fills its values from it.
	• Good use might to be to assign an old array to a more feature rich type like List with superior performance.  
	• REQ :  Array element type must match the List element type or compilation will fail.  Lookup casting in case you encounter this issue. 


*/


//using System;
//using System.Collections.Generic;

class Program
{

	static void Main() 
	{
		int[] arr = new int[3]; //New Array with 3 elements
		arr[0] = 2; // Assigning values at index of array. 
		arr[1] = 3;
		arr[2] = 5;
		
		List<int> list = new List<int>(arr);//The array past as a parameter to the List Constructor.
		Console.WriteLine(list.Count); // 3 elements in List
	}


}