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

Rajnilari2015
Posted by Rajnilari2015 under VB.NET category on | Points: 40 | Views : 93
Let's say we have an array of integers like {78,92,44,63,71,97}. The objective is to find the second largest even 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 secondLargetEven = intCollection.Where(Function(i) i Mod 2 Is 0).OrderByDescending(Function(o) o).Skip(1).Take(1).First()
Console.WriteLine("Second largest Even Number is {0}", secondLargetEven)
Console.ReadKey()
End Sub
End Class
End Namespace


Result
---------
Second largest Even Number is 78

Comments or Responses

Login to post response