Equality comparison between multiple variables

前端 未结 14 1302
梦毁少年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: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))
    

提交回复
热议问题