我需要在存储在数组中的所有整数中找到大于 0 的最小值。我在stackoverflow上尝试了一些方法,但在所有情况下我的最小值仍然等于0。我应该在我的代码中进行哪些更改才能使其正常工作?
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);
}
}
}
我想在不使用 LINQ 的情况下做到这一点。