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>开发者_StackOverflow社区;();
foreach (string num in num_list.Split(';'))
foo.Add(Convert.ToInt32(num));
Thanks, PaulH
List<int> foo = num_list.Split(';').Select(num => Convert.ToInt32(num)).ToList();
num_list.Split(';').Select( o => int.Parse(o)).ToList();
精彩评论