Home »
VB.Net »
VB.Net Programs
VB.Net program to get distinct elements from the list using Distinct() LINQ extension method
By Nidhi Last Updated : November 15, 2024
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 »