相关疑难解决方法(0)

使用条件?:(三元)运算符的好处

与标准的if-else语句相比,?:运算符有什么好处和缺点.显而易见的是:

有条件的?:运营商

  • 在处理直接价值比较和分配时更简洁,更简洁
  • 似乎不像if/else构造那样灵活

标准If/Else

  • 可以应用于更多情况(例如函数调用)
  • 通常是不必要的长

根据声明,可读性似乎各不相同.在第一次接触到?:运算符后的一段时间内,我花了一些时间来精确地消化它是如何工作的.您是否会建议尽可能使用它,或者坚持if/else,因为我与许多非程序员一起工作?

c# conditional-operator

101
推荐指数
10
解决办法
16万
查看次数

按位和C编程

我可以请一些帮助理解一下,如果是速记吗?我评论了我的想法.

//Bitwise AND not sure how it decides 32 or 0, then set board[i]    
board[i] = (randNum & 1024) ? 32 : 0;

//it the j variable j in the neighborOffset array, then mods it by 2048
//then takes that variable from the board array, then shifts 1 to 32
//then bitwise and of those 2 variables.
if(board[(i + neighborOffset[j]) % 2048] & (1 << 5))

//Not sure about this one. Can someone please explain it? 
board[i] |= ((board[i] ^ …
Run Code Online (Sandbox Code Playgroud)

c

4
推荐指数
1
解决办法
785
查看次数

标签 统计

c ×1

c# ×1

conditional-operator ×1