集合与lamdba
List<int> iList = new List<int>() { 1, 2, 3, 4, 5 }; List<int> iList2 = iList.ConvertAll<int>(i => (i + 5)); /* foreach (int k in iList2) { Console.WriteLine(k.ToString()); } * */ iList2.ForEach(i => Console.WriteLine(i.ToString())); Console.ReadLine();
2
static void Main() { List<int> list = new List<int>(new int[] { 19, 23, 29 }); // Finds first element greater than 20 int result = list.Find(item => item > 20); Console.WriteLine(result); }
3
static void Main(string[] args) { List<int> iList = new List<int>() { 1, 2, 3, 4, 5 }; List<int> iList2 = iList.FindAll(i => i > 3); iList2.ForEach(i => Console.WriteLine(i.ToString()));
// List<int> iList2 = iList.Where(i => i > 3).ToList<int>();
Console.ReadLine(); // 4,5 }
浙公网安备 33010602011771号