Create List of int from int array - CSharp Collection

CSharp examples for Collection:List

Description

Create List of int from int array

Demo Code

using System;//from ww  w  . j a v a  2 s . c o m
using System.Collections.Generic;
class Program
{
   static void Main(string[] args)
   {
      int[] numbers = { 1, 2, 3 };
      List<int> numList = new List<int>(numbers); // Initializing from an array, or...
      Console.WriteLine("\nInitialize a List<int> from another List<int>: ");
      List<int> numList2 = new List<int>(numList);
      Console.WriteLine("Resulting list: ");
      foreach (int i in numList2)
      {
         Console.WriteLine(i);
      }
   }
}

Result


Related Tutorials