ADVERTISEMENT
ADVERTISEMENT

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

Here, we are going to demonstrate the OfType() LINQ extension method in VB.Net.
Submitted by Nidhi, on January 24, 2021

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 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 »



ADVERTISEMENT




ADVERTISEMENT


Comments and Discussions!

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.