在C#中是否有小于和大于的速记?

时间:2016-06-09 09:18:19

标签: c# expression shorthand

这是否有简写:

bool b = (x > 0) && (x < 5);

类似的东西:

bool b = 0 < x < 5;

在C#中?

2 个答案:

答案 0 :(得分:6)

不。但你可以删除括号:

bool b = 0 < x && x < 5

或玩数学:

bool b = x*x < 5*x

答案 1 :(得分:0)

LINQ解决方案,不短但更易读:

addEventListener(document, "touchstart", function(e) {
    console.log(e.defaultPrevented);  // will be false
    e.preventDefault();   // does nothing since the listener is passive
    console.log(e.defaultPrevented);  // still false
  }, Modernizr.passiveeventlisteners ? {passive: true} : false);