Find a Nth highest or lowest numbers in a given series of integers using Take and Single Extension methods Of C#

Rajnilari2015
Posted by Rajnilari2015 under C# category on | Points: 40 | Views : 119
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
//Question #3: Find a Nth highest or lowest number in a given series of numbers.
List<double> lstNumbers = new List<double>() { 1, 2.06, -36.4, -4, 5.90, 61.9, 79.8, 8, 9, 18.0,23.7 };

double minNum = lstNumbers.OrderBy(o => o).Take(1).Single();
double maxNum = lstNumbers.OrderByDescending(o => o).Take(1).Single();
Console.WriteLine("Min = {0} , Max = {1}", minNum, maxNum);

Console.ReadKey(true);
}
}
}

Comments or Responses

Login to post response