ignaciofuentes ignaciofuentes - 1 year ago 84
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();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download