是什么运算符是表示表达式的属性吗?

时间:2019-05-01 11:47:40

标签: c# operators

是什么?运算符表示如下语句:

public int IntProperty => (booTrue ? 1 : 0) | (fooTrue ? 2 : 0);

我熟悉=>和?但我从未见过|这样使用。

1 个答案:

答案 0 :(得分:1)

它是bitwise or。如果我们查看您代码中的值,您可能会:

  • 0 => Array ( [0] => Array ( [id] => 1 [name] => p1 [children] => Array ( [0] => Array ( [id] => 1 [parent_id] => 1 [name] => c1 ) [1] => Array ( [id] => 2 [parent_id] => 1 [name] => c2 ) ) ) [0] => Array ( [id] => 2 [name] => p2 [children] => Array ( [0] => Array ( [id] => 1 [parent_id] => 2 [name] => c3 ) ) ) )
  • 1 => 00
  • 2 => 01

因此,如果10为true并且booTrue为true,它将为fooTrue。由于是按位运算,所以它是1 | 2 => 01 | 10(十进制=> 3)。

相关问题