ignaciofuentes ignaciofuentes - 1 year ago 43
C# Question

How can I convert comma separated string into a List<int>

string tags = "9,3,12,43,2"

List<int> TagIds = tags.Split(',');


This doesnt work cause the split method returns a string[]

Please help.

Answer Source

Here is one way of doing it:

List<int> TagIds = tags.Split(',').Select(int.Parse).ToList();