I'm beginner C# programmer and I find myself a problem in a Windows Form Application that I'm working on Microsoft Visual C# 2010 Express. I have a button that opens a file dialog to select a specific Excel workbook and then retrieve the values of the first column and the fith column to a string like this:
string x = {"120,123,125,128,130,140,157,189,220,230,243,250"}
Then I've transformed this string and add to a list of string. Here is the code:
var y = string.Join(string.Empty, x).Split(',');
List<string> listX = new List<string>();
foreach (var x1 in y)
{
listX.Add(x1);
}
The list format is like this:
listX1[0] = "120";
listX1[1] = "123";
listX1[2] = "125";
And so on. Now I have this method to count how many number are between, lets say, 123 and 150, which will give me the number of 5 (with 123 included). The method used is something like this:
public static int Count(IList<int> set, int min, int max)
{
int count = 0;
foreach (int i in set)
if( i <= max && i >= min)
count++
return count;
}
Where min in this case would be 123 and max would be 150.
Now I know that I can't use this method because my list (listX1) is a list of strings. How can I manage to count the numbers between min and max, using C#? Anyone can help me with that?
Hope you can help me. Many Thanks.