string ids="5,1,6,3,5,7,8,9,1,5,6,"
var temp = ids.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Select(a=>a.ToInt()).ToArray();
==>temp=[5,1,6,3,5,7,8,9,1,5,6]
————————————————
string str = "1,2,3,4,5,6,7";
string[] strArray = str.Split(','); //字符串转数组
str = string.Empty;
str = string.Join(",", strArray);//数组转成字符串
//声明数组. 第一种方法. 声明并分配元素大小. 13 int[] Myint = new int[30]; 14 Myint[0] = 30; 15 Myint[1] = 50; 16 // 以此类推, 起始下标为0 17 //------------------------------- 18 // 声明数组,第二种方法, 声明并直接赋值,没有指定元素大小. 19 int[] Myint1 = { 20,10,50,65,18,90}; 20 //------------------------------------------ 21 //声明数组,第三种方法, 声明并分配大小,且赋值. 22 int[] i = new int[5] { 10, 20, 30, 40, 50 }; 23 24 // ----------------------------------------------- 25 // foreach循环遍历数组.. 26 int[] Sum = new int[50]; 27 Random rd = new Random(); 28 // 先用for循环给数组取随机数. 29 for (int s = 0; s <= Sum.Length - 1; s++) // Sum.Length是数组的一个属性,Length代表数组的长度 30 { 31 Sum[s] = rd.Next(100); 32 } 33 // 遍历数组输出 34 foreach (int t in Sum) 35 { 36 Console.WriteLine(t); 37 }