c# convert to list code example

Example 1: string to list c#

var names = "Brian,Joe,Chris";
List<string> result = names.Split(',').ToList();

Example 2: c# array to list

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

Example 3: 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 };

Example 4: to list c#

var arr = new int[] {1, 2, 3};
List<int> list = arr.ToList();