Using Conversion Operator in LINQ: Part1

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

        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          

           2..1.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

             2.2.gif

Read More articles related LINQ Click Here