Split string, convert ToList<int>() in one line

uzay95 picture uzay95 · May 26, 2009 · Viewed 197.1k times · Source

I have a string that has numbers

string sNumbers = "1,2,3,4,5";

I can split it then convert it to List<int>

sNumbers.Split( new[] { ',' } ).ToList<int>();

How can I convert string array to integer list? So that I'll be able to convert string[] to IEnumerable

Answer

mqp picture mqp · May 26, 2009
var numbers = sNumbers.Split(',').Select(Int32.Parse).ToList();