ignaciofuentes ignaciofuentes - 4 months ago 15
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

Here is one way of doing it:

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