我正在尝试使用光滑的单衬垫,因为我觉得这可能是可能的。
我将把我的代码放在下面,然后尝试更多地解释我想要实现的目标。
for (int p = 0; p < 2; p++)
{
foreach (string player in players[p])
{
if (PlayerSkills[player].streak_count *>* 0) //This line
PlayerSkills[player].streak_count++;
else
PlayerSkills[player].streak_count = 0;
}
}
*(p==0 ? >:<) 根据 p 选择比较运算符。
当然我写的是垃圾。但基本上我想在 p==0 时使用 >0,在 p>>0 时使用 <0。有实现此目标的好方法吗?
最佳答案
好吧,您应该使用最易读的内容,即使它不是那么合理。也就是说……
// Invert the count for all but the first player and check for a positive number
if (PlayerSkills[player].streak_count * (p==0 ? 1 : -1) > 0)
关于C#:根据 bool 值选择运算符(一行),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24191789/