×

VB.Net Programs

VB.Net program to demonstrate the OfType() LINQ extension method

By Nidhi Last Updated : November 13, 2024

VB.Net – OfType() LINQ Extension Method

In this program, we will use OfType() LINQ extension method to get the string elements from the array list and print them on the console screen.

Program/Source Code:

The source code to demonstrate the OfType() LINQ extension method is given below. The given program is compiled and executed successfully.

VB.Net code to demonstrate the example of OfType() LINQ Extension Method

'VB.NET program to demonstrate the 
'OfType() LINQ extension method.

Imports System
Imports System.IO
Imports System.Linq

Module Module1
    Sub Main()
        Dim lst As New ArrayList()

        lst.Add(101)
        lst.Add("India")
        lst.Add("USA")
        lst.Add(201)

        Dim Result = lst.OfType(Of String)()

        Console.WriteLine("Result: ")
        For Each str As String In Result
            Console.WriteLine(vbTab & str)
        Next
    End Sub
End Module

Output

Result:
        India
        USA
Press any key to continue . . .

Explanation

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

In the Main() function, We created an array list that contains mixed elements that may be integer or string. Here, we used OfType() LINQ extension method to find out the string elements from the array list and then print them on the console screen.

VB.Net LINQ Query Programs »


Comments and Discussions!

Load comments ↻





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