我正在尝试做一些类似的事情
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