/// <summary> /// 理解Lambda表达式 /// </summary> /// <param name="args"></param> static void Main(string[] args) { List<String> user = new List<String> { "panda", "bigpanda", "xxpanda", "bigbigxx" };//初始化 var results = user.Where(m => m.Contains("g")).Select(m => m); foreach (var item in results) { Console.WriteLine(item.ToString()); } //----------------------------------------------------------- var result = from w in user where w.Contains("g") select w; foreach (var item in results) { Console.WriteLine(item.ToString()); } //----------------------------------------------------------- List<int> ageList = new List<int> { 10, 15, 18, 10, 50 }; var aveAge = ageList.Average(m => m); Console.WriteLine(aveAge); //---------------------------------------------------------- var avgAge = from x in ageList select x; Console.WriteLine(avgAge.Average()); }