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

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