This post will discuss how to convert a comma-separated string into a list in C#.

To convert a delimited string to a sequence of strings in C#, you can use the String.Split() method. Since the Split() method returns a string array, you can convert it into a List using the ToList() method. You need to include the System.Linq namespace to access the ToList() method.

Download  Run Code

 
Alternately, you can use the List<T> constructor to convert the string[] into a List<String>. This does not require LINQ.

Download  Run Code

 
The above solution returns a list of strings. If you need to convert the list of strings to another data type, say integer, you can use LINQ’s Select() method.

Download  Run Code

 
If you don’t want to use LINQ, try using the Array.ConvertAll() method for converting an array to a list of a different type. This translates to:

Download  Run Code

That’s all about converting a comma-separated string into a List in C#.