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

nacho10f picture nacho10f · Feb 15, 2012 · Viewed 286.5k times · Source
string tags = "9,3,12,43,2"

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

This doesn't work cause the split method returns a string[]

Answer

Sergey Kalinichenko picture Sergey Kalinichenko · Feb 15, 2012

Here is one way of doing it:

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