C# Program to find the numbers between a range

Rajnilari2015
Posted by Rajnilari2015 under C# category on | Points: 40 | Views : 221
Let's say we have a collection as { 16, 17, 4, 3, 5, 2,10 }. Given a range 2,10 we need to find out the numbers between the range. The range values are inclusive. The below program will do so

using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
var intList = new List<int>() { 16, 17, 4, 3, 5, 2,10 };
var lowerRange = 2;
var upperRange = 10;

intList
.Where(w => w >= 2 && w <= 10)
.OrderBy(o=>o)
.ToList()
.ForEach(i => Console.WriteLine(i));

Console.ReadKey();
}
}
}


Result
-------

2
3
4
5
10

Comments or Responses

Login to post response