How to convert the C# GroupBy to VB.NET?

Steven Young 261 Reputation points
2021-01-28T08:12:27.467+00:00

How to convert the C# code to VB.NET?
var possibleDuplicateFiles = files.GroupBy(f => f.Length).Where(s => s.Count() > 1).SelectMany(f => f).ToList()

Thank you

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,594 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Peter Fleischer (former MVP) 19,231 Reputation points
    2021-01-28T14:25:00.547+00:00

    Hi,
    for C#:

    var possibleDuplicateFiles = files.GroupBy(f => f.Length).Where(s => s.Count() > 1).SelectMany(f => f).ToList()
    

    in VB.NET you get:

      Dim possibleDuplicateFiles = files.GroupBy(Function(f)
                                                   Return f.Length
                                                 End Function).Where(Function(s)
                                                                       Return s.Count > 1
                                                                     End Function).SelectMany(Function(f)
                                                                                                Return f
                                                                                              End Function).ToList
    

    or

      Dim possibleDuplicateFiles = files.GroupBy(Function(f) f.Length).Where(Function(s) s.Count > 1).SelectMany(Function(f) f).ToList
    
    0 comments No comments

  2. Sam of Simple Samples 5,516 Reputation points
    2021-01-28T18:55:22.71+00:00

    You can use C# to VB.NET Converter for free for output up to 100 lines per file. There is a snippet option that can convert snippets such as you are asking about.

    0 comments No comments