Write a program in VB.net to find the product of negative numbers from a collection of numbers

Rajnilari2015
Posted by Rajnilari2015 under VB.NET category on | Points: 40 | Views : 116
Given an collection as -8, -7, 6, 0, 7, -1, 6. The objective is to find the product of negative numbers from the collection of numbers. The below program will do so

Imports System.Collections.Generic
Imports System.Linq

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

Console.WriteLine(New List(Of Integer)() From { _
-8, _
-7, _
6, _
0, _
7, _
-1, _
6 _
}.OrderBy(Function(o) o).TakeWhile(Function(t) t < 0).Aggregate(Function(a, b) a * b))

Console.ReadKey()
End Sub

End Class
End Namespace

Output: -56

Comments or Responses

Login to post response