Linq SelectMany和Select的区别

  //IEnumerable.Select 将序列中的Authors元素投影到新表中.
            IEnumerable> EnumerableOfListOfAuthors = Books.Select(book => book.Authors);

            foreach (var listOfAuthors in EnumerableOfListOfAuthors)
            {
                foreach (Author auth in listOfAuthors)
                {
                    Output.Items.Add(auth.Name); //添加到ListBox里面
                }
            }

            //IEnumerable.SelectMany  将序列的每个元素投影到 IEnumerable 并将结果序列合并为一个序列。
            IEnumerable authors = Books.SelectMany(book => book.Authors);
            foreach (Author auth in authors)
            {
                Output2.Items.Add(auth.Name);
            }

你可能感兴趣的:(Linq语句学习)