【发布时间】:2012-02-03 16:04:58
【问题描述】:
可能重复:
Split string, convert ToList<int>() in one line
Convert comma separated string of ints to int array
我有一个像这样的字符串:
string test = "1,2,3,4";
有没有更简单的方法(在语法上)将其转换为 List<int> 相当于这样的东西:
string[] testsplit = test.Split(',');
List<int> intTest = new List<int>();
foreach(string s in testsplit)
intTest.Add(int.Parse(s));
【问题讨论】:
-
喜欢“拆分”它吗?我已经更新了标签,以便您解决相关问题。
-
从没见过这么多相同的答案,天哪。