let:
String[] strs = { "A penny saved is a penny earned.", "The early bird catches the worm.", "The pen is mightier than the sword." }; var result = from s in strs //s是数组strs中的一个元素 let word = s.Split(' ') //word是s句子中的单词数组 from a in word //a是word单词数组中的一个单词 let w = a.ToLower() //w是a单词的小写 where w[0] == 't' select word; foreach (var r in result) { var words = r.ToArray(); foreach (var w in words) { Console.Write(w + "||"); } Console.WriteLine(); Console.WriteLine("======================="); }
2.concat:
连接数组
var result = list.Select(q => q.Name).Concat(dogs.Select(o => o.Name)); ap.ShowArray(result.ToArray());
注意必须都是同一类型的,例如上面就是字符串类型
连接对象数组
var result = list.Where(q => q.ID < 4); var result2 = list.Where(q => q.ID > 7); var result3 = result.Concat(result2); ap.Show(result3.ToList());
有相同数据的情况
var result = list.Where(q => q.ID < 8); var result2 = list.Where(q => q.ID > 4); var result3 = result.Concat(result2); ap.Show(result3.ToList());