标签:style blog ar color sp for on div log
1 static void Main(string[] args) 2 { 3 List<int> integers = new List<int>(); 4 for (int i = 1; i < 5; i++) 5 { 6 integers.Add(i); 7 } 8 Converter<int, double> converters = TakeSquareRoot;//创建委托实例 9 List<double> doubles; 10 doubles = integers.ConvertAll<double>(converters);//调用泛型方法转换列表 11 foreach (var item in doubles) 12 { 13 Console.WriteLine(item); 14 } 15 16 Console.ReadKey(); 17 } 18 19 public static double TakeSquareRoot(int x) 20 { 21 return Math.Sqrt(x); 22 }
《深入理解C#》代码片段-List<T>.ConvertAll(TOutput)方法实战
标签:style blog ar color sp for on div log
原文地址:http://www.cnblogs.com/Ares945/p/convert.html