Home » Programming » LINQ » Story Details
Printable Version

LINQ Conversion and Generation operators in VB.NET

by kimi kalon on Sep 28, 2011

Here, we will learn how to use Conversion and Generation Operators in LINQ.
Download Files: conversionandgenerationoperator.zip
Comments: 0    Views: 399

Conversion operator

The Conversion operator of LINQ is a operator which is used Four ways simple ToArray, ToList, ToDictionary and OfType. In this article first we discuss about First two categories.

First we discuss about the ToArray operator by using a simple example. you can write this code in vb.net and by getting the output you understand the working of Average .

EXAMPLE CODE          

Module Module1
    Sub Main()
        Dim Numbers() = {7.8, 4.6, 9.0, 1.1, 10.7}
        Dim SortedList = From c In Numbers Select c Order By c
Descending
        Dim Arrays = SortedList.ToArray()
        Console.WriteLine("All Numbers from highest to lowest:")
        For c As Integer = 0 To Arrays.Length
            Console.WriteLine(Arrays(c))
            c += 1
       
Next
        Console.ReadLine()
    End
Sub

End
Module

 OUTPUT       

conversionfun1.gif

The second category of Conversion operator is ToList. This operator is evaluating a sequence into a list.

EXAMPLE CODE

Module Module1
    Sub Main()
        Dim Names() = {"ajay", "rahul", "manish", "ravi", "raj"}
        Dim sortedList = From a In Names Select a Order By a
        Dim List = sortedList.ToList()
        Console.WriteLine("The sorted list:")
        For Each a In List
            Console.WriteLine(a)
        Next
        Console.ReadLine()
    End Sub

End Module               

OUTPUT

conversionfun2.gif 

Generation operators

Generation operators are the operators in LINQ which are use to produce an range and repetition of result. These are two types Range Operator and Repeat Operator. In this article we discuss about these two categories of the Generation Operators.

First we discuss about the Range operator by using a simple example. you can write this code in vb.net and by getting the output you understand the working of Range operator.

EXAMPLE CODE          

Module Module1
    Sub Main()
        Dim Values = From n In Enumerable.Range(1, 20) Select No = n, OddEven = If(n Mod 2 = 1, "odd", "even")
        For Each n In Values
            Console.WriteLine("The number {0} is {1}.", n.No, n.OddEven)
        Next
        Console.ReadLine()
    End Sub

End
Module

OUTPUT   

Generation1.gif   

The second and Last category of Generation operator is Repeat. It repeats the result according to your given parameter.

EXAMPLE CODE

Module Module1
    Sub Main()
        Dim Value = Enumerable.Repeat(5, 6)
        For Each a In Value
            Console.WriteLine(a)
        Next
        Console.ReadLine()
    End Sub

End
Module

OUTPUT

Generation2.gif

Post a Comment
*
DevExpress PowerBuilder Web Development Windows Development Languages Software Engineering Databases
iPhone Architecture Secutiry UML & Modeling Operating Systems Networking Testing
Graphics Design Project Management Hardware Open Source Games Development Business Intelligence Visual Studio LightSwitch 2011
MonoDevelop Visual Studio 2010 ASP.NET HTML, DHTML XML PHP JavaScript
Silverlight Web Services WCF Windows Forms WPF Windows Services Dynamic Link Libraries
ActiveX COM, DCOM, ATL C# VB.NET C++ F# Java
Pascal SQL Server Oracle DB2 MS-Access Windows Servers Windows
Linux Unix SAP LINQ .NET Framework ADO.NET Reporting
Crystal Reports SQL Server Reporting Services Igenda Reports Active Reports Adobe Fireworks Arrays & Collections Hosting
Future Trends Android Windows Phone Smart Devices Business M&A Investment & Funding
Web Browsers Internet Explorer Firefox Safari Common Entrepreneurs Students
Consulting Wiki Gadgets MobileMe iCloud iOS Social Media
Facebook Twitter LinkedIn Google+ Microsoft Kinect XBox
Wii Playstation DirectX i OS OS X CIO, CTO, CEO Windows 8
Web Design Expression Blend 4 Photoshop CS5 Creative Suite 5.5 Expression Web 4 Expression Studio 4 Creative Suite® 5.5 Design
Creative Suite 5.5 Web Creative Suite 5.5 Production Startups Funding M&A Laptops Smart Phones
Desktops Cameras & Camcorders Netbooks Tablets Virtualization Microsoft Surface WordPress
Software Products Cloud Computing Current Affairs Technology TV TV
Earnings XAML E-Commerce MonoTouch Mono for Android Deals Electronics
Mobile Phone Laptop Tablet Book Computer Press Releases Reviews
Products Books Companies Windows Azure SQL Azure Interviews Mac
Web Browsers Symbian Windows Forms WPF Windows Services HTML 5 Office 365
SharePoint 2010 Exchange Server Adobe Visual Studio 2012 iPad Flex / Flash Games
Windows 9
X
 Login
Please login to submit a new post, reply and edit exiting posts, see user profiles, and access more features. If you are not a registered member, Register here.
User Id / Email:
Password:  
Forgot Password | Forgot UserName