c#数组类型转换

 

代码
 1 static void Main(string[] args)
 2 {
 3     string[] a = new string[] { "1""2""3" };
 4 
 5     //方法一
 6     int[] b = Array.ConvertAll(a, new Converter<stringint>(StrToInt));
 7 
 8     //方法二
 9     int[] c = Array.ConvertAll<stringint>(a, delegate(string n) { return int.Parse(n); });
10 }
11 public static int StrToInt(string str)
12 {
13     return int.Parse(str);
14 }

 

 

posted @ 2010-08-26 19:19  chqyang  阅读(784)  评论(0编辑  收藏  举报