What's the false operator in C# good for?

前端 未结 5 1558
無奈伤痛
無奈伤痛 2020-11-30 18:21

There are two weird operators in C#:

  • the true operator
  • the false operator

If I understand this right these operators can be used in typ

5条回答
  •  醉酒成梦
    2020-11-30 18:59

    Shog9 and Nir: thanks for your answers. Those answers pointed me to Steve Eichert article and it pointed me to msdn:

    The operation x && y is evaluated as T.false(x) ? x : T.&(x, y), where T.false(x) is an invocation of the operator false declared in T, and T.&(x, y) is an invocation of the selected operator &. In other words, x is first evaluated and operator false is invoked on the result to determine if x is definitely false. Then, if x is definitely false, the result of the operation is the value previously computed for x. Otherwise, y is evaluated, and the selected operator & is invoked on the value previously computed for x and the value computed for y to produce the result of the operation.

提交回复
热议问题