string[] 转int[] 的方法

首先感谢群里一位兄弟老A,让我更加熟悉了string[] 转int[] 方法。废话不多说,直接贴代码:

背景:

string[] listString = new string[] { "1", "2", "3" };


方法1-迭代:

  int[] c = new int[listString.Length];  

09     for(int i = 0; i <  listString.Length; i++) {  

10         c[i] = Convert.ToInt32( listString[i].ToString());  

11     }  

12     return c;  

方法2-linq:

int[] _lists = listString.Select(int.Parse).ToArray();

反之int[] 转string[] 也是同样道理 也可以转成IEnumerable,List等。记下,送给同样需要的兄弟

posted on 2013-05-10 12:19  ~紫鱼~  阅读(465)  评论(0编辑  收藏  举报