array to list c# code example

Example 1: convert string array to int C#

using System;

public class Example
{
	public static void Main()
	{
		string[] strings = new string[] {"1", "2", "3"};

		int[] ints = Array.ConvertAll(strings, s => int.Parse(s));
		Console.WriteLine(String.Join(",", ints));
	}
}

Example 2: c sharp array to list

var list = new List<int>(array);

Example 3: C# list to array

string[] array = list.ToArray();

Example 4: c# array to list

var intArray = new[] { 1, 2, 3, 4, 5 };
var list = new List<int>(intArray);

Example 5: array to list C

using System.Linq;

int[] ints = new [] { 10, 20, 10, 34, 113 };

List<int> lst = ints.OfType<int>().ToList(); // this isn't going to be fast.

OR

List<int> lst = new List<int> { 10, 20, 10, 34, 113 };