为了教育目的,我尝试将以下
Linq表达式从“
Linq in action”转换成VB.net
原始C#
var list = from book in SampleData.Books group book by new { book.Publisher.Name,book.Subject } into grouping select new { Publisher = grouping.Key.Publisher,Subject = grouping.Key.Subject,Book = grouping };
我的尝试:
Dim list = _books.GroupBy(Function(book) New With {.Publisher = book.Publisher.Name,book.Subject}). Select(Function(grouping) New With {.Publisher = grouping.Key.Publisher,.Subject = grouping.Key.Subject,.Books = grouping}) For Each item In list Console.WriteLine("Publisher:" & item.Publisher & ",Subject:" & item.Subject) For Each Book In item.Books Console.WriteLine(" " & Book.Title) Next Next
这将导致以下输出:
Publisher:FunBooks,Subject:Fun Funny Stories Publisher:Joe Publishing,Subject:Work LINQ rules Publisher:Joe Publishing,Subject:Work C# on rails Publisher:Joe Publishing,Subject:Fun All your base are belong to us Publisher:FunBooks,Subject:Fun Bonjour mon Amour
我预计,“LINQ规则”和“C#在轨道”上的书籍都被分组,以及书籍“滑稽故事”和“Bonjour mon Amour”,因为它们具有相同的发行者和主题.
我的匿名密钥包含两个简单字符串的新对象.
我已经尝试搜索SO,但other(or)的答案不解决我的问题.即使像telerik或carlosag这样的代码转换器在这种情况下也没有帮助.