OrderBy and Repeat operator in Linq using VB.NET

Here we will see how to use OrderBy and Repeat Operator in LinQ.
  • 3718

OrderBy Operator

OrderBy operator is used to sort the elements of a sequence in ascending order.

For example

The following query emits a sequence of names in alphabetical order.

Module Module1

    Sub Main()

        Dim names As String() = {"Rohatash", "Monu", "Ajay", "Vijay", "Ram", "Hari", "vikash", "ravi", "sarvan", "kavita"}

        Dim query As IEnumerable(Of String) = names.OrderBy(Function(s) s)

        For Each s As [String] In query

            Console.WriteLine(s)

        Next

    End Sub

End Module

OUTPUT

orderby-operator.gif
 

Repeat operator

Repeat operator accepts the number to repeat, and the number of iterations.

This defines the repeat operator.

For Each i As Integer In Enumerable.Repeat(7, 4)
Console.WriteLine(i & " ")

In the above example repeat operator repeat 7 four times.

For example

Module Module1

    Sub Main()

        For Each i As Integer In Enumerable.Repeat(7, 4)

            Console.WriteLine(i & " ")

        Next

    End Sub

End Module

OUTPUT

Repeat-operator.gif

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.