I need to find the smallest value which is larger than 0 among all integers stored in an array. I tried some of the ways of doing that on stackoverflow, but my minimal value still equals to 0 in all cases. What should I change in my code to make it work?
int[] userInput = new int[1000];
int counter;
Console.WriteLine ("Please input some numbers");
for (counter = 0; counter < userInput.Length; counter++) {
string line = Console.ReadLine ();
if (line == "" || line == "stop") {
break;
} else {
int.TryParse (line, out userInput [counter]);
}
}
int min = 0;
for(int i = 0; i < userInput.Length; i++)
{
if(userInput[i] > 0)
{
userInput[i] = min;
break;
}
}
for(int i = 0; i < userInput.Length; i++)
{
if(userInput[i] < min && userInput[i] > 0)
{
min = userInput [i];
}
}
Console.WriteLine(min);
}
}
}
I would like to do it without using LINQ.