Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

Copying Array to a List in C#

Without using LINQ, we can copy a array to a list.

Example:
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace forgetCode
  5. {
  6. class program
  7. {
  8. public static void Main()
  9. {
  10. int[] array = new int[3]; // New array with 3 elements
  11. array[0] = 10;
  12. array[1] = 20;
  13. array[2] = 30;
  14. List<int> list = new List<int>(array); // Copy to List
  15. Console.WriteLine(list.Count);
  16. }
  17. }
  18. }


Output:
3