我有 2 个不同的课程
class TollGate
{
public void Check(int []numbers, int Token)
{
int i;
for (i = 0; i < numbers.Length; i++)
{
int s = numbers[i];
if ( Token > s)
{
Console.WriteLine("You Got To Wait");
return;//this works
}
else
{
Console.WriteLine("Hold On Printing a Pass\n\"Happy Trip\"");//this doesn't
return;
}
}
}
}
class Program
{
public static void Main()
{
int[] numbers = new int[5] {1, 2, 3, 4, 5};
Random rnd = new Random();
int r = rnd.Next(numbers.Length);
int Token = (numbers[r]);
Tollgate T = New TollGate();
T.Check(numbers, Token);
Console.WriteLine("Cool");
Console.WriteLine("Hot");
Console.WriteLine("Freezing");
}
}
我不能使用两个返回语句。如何让它停止,只给出一次消息,但它只是与循环一起显示它与循环一样多次。