Find a Nth highest or lowest numbers in a given series of integers using Take and Single Extension methods Of VB.net

Rajnilari2015
Posted by Rajnilari2015 under VB.NET category on | Points: 40 | Views : 133
Imports System.Collections.Generic
Imports System.Linq

Namespace ConsoleApplication2
Class Program
Private Shared Sub Main(args As String())
'Question #3: Find a Nth highest or lowest number in a given series of numbers.
Dim lstNumbers As New List(Of Double)() From { _
1, _
2.06, _
-36.4, _
-4, _
5.9, _
61.9, _
79.8, _
8, _
9, _
18.0, _
23.7 _
}

Dim minNum As Double = lstNumbers.OrderBy(Function(o) o).Take(1).[Single]()
Dim maxNum As Double = lstNumbers.OrderByDescending(Function(o) o).Take(1).[Single]()
Console.WriteLine("Min = {0} , Max = {1}", minNum, maxNum)

Console.ReadKey(True)
End Sub
End Class
End Namespace

Comments or Responses

Login to post response