Program to find the second largest odd number in VB.net

Rajnilari2015
Posted by Rajnilari2015 under VB.NET category on | Points: 40 | Views : 890
Let's say we have an array of integers like {78,92,44,63,71,97}. The objective is to find the second largest odd number. Below program will do so

Imports System.Collections.Generic
Imports System.Linq

Namespace ConsoleApplication2
Class Program
Private Shared Sub Main(args As String())

Dim intCollection = New List(Of Integer)() From { _
78, _
92, _
44, _
63, _
71, _
97 _
}
Dim secondLargetOdd = intCollection.Where(Function(i) i Mod 2 IsNot 0).OrderByDescending(Function(o) o).Skip(1).Take(1).First()
Console.WriteLine("Second largest Odd Number is {0}", secondLargetOdd)
Console.ReadKey()
End Sub
End Class
End Namespace

Result
---------
Second largest Odd Number is 71

Comments or Responses

Login to post response