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();

  

转载于:https://www.cnblogs.com/tinya/p/4505578.html

你可能感兴趣的:(String str = "1,2,3,4,5,6" 如何将这个字符串转换成int数组)