不能丢弃 val1 和 val2 的结果吗?

  • 本文关键字:结果 val2 val1 不能 c#
  • 更新时间 :
  • 英文 :


我正在尝试做一些类似的事情

public class Program
{
private static readonly Random r = new Random();
public static void Main()
{
RandomBool() && RandomBool();
}
private static bool RandomBool()
{
bool b = r.Next() % 2 == 0;
Console.WriteLine("Random bool value is {0}", b);
return b;
}
}

即执行CCD_ 1直到它是CCD_。(您可以在JavaScript中执行此操作(

我想我必须做

public static void Main()
{
bool throwAwayValue = RandomBool() && RandomBool();
}

或者有更好的方法来做同样的事情吗?

如果你想重复执行RandomBool直到它为false,你不能在main中使用while循环吗?

while (RandomBool()) { 
// wait
}

https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/while

最新更新