Linq let Concat

扫码查看

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[] == 't'
select word;
foreach (var r in result)
{
var words = r.ToArray();
foreach (var w in words)
{
Console.Write(w + "||");
}
Console.WriteLine();
Console.WriteLine("=======================");
}

Linq let Concat-LMLPHP

2.concat:

连接数组

var result = list.Select(q => q.Name).Concat(dogs.Select(o => o.Name));
ap.ShowArray(result.ToArray());

Linq let Concat-LMLPHP

注意必须都是同一类型的,例如上面就是字符串类型

连接对象数组

var result = list.Where(q => q.ID < );
var result2 = list.Where(q => q.ID > );
var result3 = result.Concat(result2);
ap.Show(result3.ToList());

Linq let Concat-LMLPHP

有相同数据的情况

   var result = list.Where(q => q.ID < );
var result2 = list.Where(q => q.ID > );
var result3 = result.Concat(result2);
ap.Show(result3.ToList());

Linq let Concat-LMLPHP

05-11 18:14
查看更多