String str = "1,2,3,4,5,6" 如何将这个字符串转换成int数组

String str = "1,2,3,4,5,6";
string[] strS = str.Split(',');
int[] num = new int[strS.Length];
int number, i = 0;
foreach (var item in strS)
{
if (int.TryParse(item, out number))
num[i++] = number;
}

 

String str = "1,2,3,4,5,6";
var q = str.Split(',').Select(x => int.Parse(x)).ToList();

  

posted @ 2015-05-15 12:02  天涯过者  阅读(2495)  评论(0编辑  收藏  举报