//IEnumerable<Book>.Select 将序列中的Authors元素投影到新表中.
IEnumerable<List<Author>> EnumerableOfListOfAuthors = Books.Select(book => book.Authors);
foreach (var listOfAuthors in EnumerableOfListOfAuthors)
{
foreach (Author auth in listOfAuthors)
{
Output.Items.Add(auth.Name); //添加到ListBox里面
}
}
//IEnumerable<Book>.SelectMany 将序列的每个元素投影到 IEnumerable<T> 并将结果序列合并为一个序列。
IEnumerable<Author> authors = Books.SelectMany(book => book.Authors);
foreach (Author auth in authors)
{
Output2.Items.Add(auth.Name);
}
Linq SelectMany和Select的用法
最新推荐文章于 2024-06-18 15:02:14 发布