.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> LINQ >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Seperate specific data from an Object Array using LINQ

Posted By:Hefin Dsouza       Posted Date: August 12, 2009    Points: 10    Category: LINQ    URL: http://www.dotnetspark.com  
 

This code sample will allow one to separate values of specific types using LINQ

This example WORKS WITH ONLY VB.net 9.0(VS.net 2008)


Sub Main()
Dim obj() As Object = {1, "Hefin", 100, "Initiotech", "Dsouza", True, False}
Dim onlyIntegers = obj.OfType(Of Integer)()
Dim OnlyString = obj.OfType(Of String)()
Dim onlyBoolean = obj.OfType(Of Boolean)()
Console.WriteLine("Only Integer's in The Object Array are : ")
For Each i As Integer In onlyIntegers
Console.WriteLine(i)
Next

Console.WriteLine("Only String's in The Object Array are : ")
For Each i As String In OnlyString
Console.WriteLine(i)
Next

Console.WriteLine("Only Boolean's in The Object Array are : ")
For Each i As Boolean In onlyBoolean
Console.WriteLine(i)
Next

End Sub

In the Above Sample The obj() aray contains String,Integer and boolean datatypes.
The onlyIntegers variable stores only the integer values from the obj array by using the
OfType method.

Hope This sample has helped you.

Regards
Hefin Dsouza


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend