Equality comparison between multiple variables

前端 未结 14 1105
梦毁少年i
梦毁少年i 2020-11-29 08:00

I\'ve a situation where I need to check whether multiple variables are having same data such as

var x=1;
var y=1;
var z=1;

I want to check

相关标签:
14条回答
  • 2020-11-29 08:50

    XOR might work for you, e.g. given:

    var x=1;
    var y=1;
    var z=1;
    

    Then

    x ^ y ^ z == 0
    

    Is true

    -edit- If you want to check if all values are the same and their value is 1, use:

    x ^ y ^ z ^ 1 == 0
    
    0 讨论(0)
  • 2020-11-29 08:51

    Slight variation on the excellent answer given by jevakallio above. See if myValue is equal to any of the values in a list (in the array):

    if (new[] { 10, 11, 12 }.Any(x => x == myValue))
    
    0 讨论(0)
提交回复
热议问题