locked
List(Of T) GroupBy

    Question

  • Hi, for the past hour i have tried to convert a C# code to VB and i have failed to do so, here is my C# code below

    var moviesByCategories = movies.GroupBy(x => x.Category)
                    .Select(x => new MovieCategory { Title = x.Key, Items = x.ToList() });
    

    how can i do the same thing in Visual Basic?

    Thursday, January 22, 2015 12:58 PM

Answers

  •  movies.GroupBy(Function(x) x.Category).Select(Function(x) New MovieCategory With {.Title = x.Key, .Items = x.ToList()})


    在現實生活中,你和誰在一起的確很重要,甚至能改變你的成長軌跡,決定你的人生成敗。 和什麼樣的人在一起,就會有什麼樣的人生。 和勤奮的人在一起,你不會懶惰; 和積極的人在一起,你不會消沈; 與智者同行,你會不同凡響; 與高人為伍,你能登上巔峰。

    • Marked as answer by Jay_P85 Thursday, January 22, 2015 9:10 PM
    Thursday, January 22, 2015 2:20 PM

All replies

  •  movies.GroupBy(Function(x) x.Category).Select(Function(x) New MovieCategory With {.Title = x.Key, .Items = x.ToList()})


    在現實生活中,你和誰在一起的確很重要,甚至能改變你的成長軌跡,決定你的人生成敗。 和什麼樣的人在一起,就會有什麼樣的人生。 和勤奮的人在一起,你不會懶惰; 和積極的人在一起,你不會消沈; 與智者同行,你會不同凡響; 與高人為伍,你能登上巔峰。

    • Marked as answer by Jay_P85 Thursday, January 22, 2015 9:10 PM
    Thursday, January 22, 2015 2:20 PM
  • There is a free C# to VB.NET (and vice versa) converter available here at Telerik's website here: http://converter.telerik.com/

    I don't say it is perfect but you might find this one useful in the future. Your code should look something like this:

            Dim moviesByCategories = movies.GroupBy(Function(x) x.Category).Select(Function(x) New MovieCategory() With { _
                                                                                       .Title = x.Key, _
                                                                                       .Items = x.ToList() _
                                                                                   })

    Hope that helps.

    Please remember to mark helpful posts as answer and/or helpful.

    Thursday, January 22, 2015 3:55 PM