VB.Net program to get distinct elements from the list using Distinct() LINQ extension method

Here, we are going to learn how to get distinct elements from the list using Distinct() LINQ extension method in VB.Net?
Submitted by Nidhi, on February 02, 2021 [Last updated : March 08, 2023]

VB.Net – Distinct elements from the list using Distinct() LINQ Extension Method

In this program, we will get distinct elements from the list of integers using the Distinct() LINQ extension method and print the result on the console screen.

Program/Source Code:

The source code to get distinct elements from the list using the Distinct() LINQ extension method is given below. The given program is compiled and executed successfully.

VB.Net code to get distinct elements from the list using Distinct() LINQ extension method

'VB.NET program to get distinct elements from a 
'list using Distinct() LINQ extension method.

Module Module1
    Sub Main()
        Dim intList = New List(Of Integer) From {101, 102, 103, 101, 104, 105, 105, 106}

        Dim distinctValues = intList.Distinct()

        Console.WriteLine("Distinct Elements:")
        For i = 0 To distinctValues.Count() - 1 Step 1
            Console.Write(distinctValues.ElementAt(i) & " ")
        Next
        Console.WriteLine()
    End Sub
End Module

Output

Distinct Elements:
101 102 103 104 105 106
Press any key to continue . . .

Explanation

In the above program, we created a module Module1 that contains a Main() function. The Main() function is the entry point for the program.

In the Main() function, We get the distinct elements from the list of integers using the Distinct() LINQ extension method and then print the result on the console screen.

VB.Net LINQ Query Programs »






Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.