Reputation: 7863
I have a Visual Studio 2008 C#.NET 3.5 application where I have a string with a list of numbers separated by a semicolon.
string num_list = "1;2;3;4;201;2099;84"
I would like to convert that to a List<int>
. Is there an easier way than this?
List<int> foo = new List<int>();
foreach (string num in num_list.Split(';'))
foo.Add(Convert.ToInt32(num));
Thanks, PaulH
Upvotes: 1
Views: 195
Reputation: 108957
List<int> foo = num_list.Split(';').Select(num => Convert.ToInt32(num)).ToList();
Upvotes: 5