[Solved] Count how many numbers is between a range in a List with C#


I believe you have string array like:

string[] x = { "120", "123", "125", "128", "130", "140", "157", "189", "220", "230", "243", "250" };

You have to parse each item to int and then sort them, later you can get the count like:

int start = 123;
int end = 150;
var result = x.Select(int.Parse)
              .Count(r => r >= start && r < end);

If you want to use int.TryParse then you can do:

int start = 123;
int end = 150;
int temp;
var result = x.Select(r => { return int.TryParse(r, out temp) ? temp : -1; })
              .Count(r => r >= start && r < end);

0

solved Count how many numbers is between a range in a List with C#