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
if (x == y && y == z && z == 1)
is the best you can do, because
y == z
evaluates to a boolean and you can't compare x
with the result:
x == (y == z)
| |
int bool
I would do this:
public bool AllEqual(params T[] values) {
if(values == null || values.Length == 0)
return true;
return values.All(v => v.Equals(values[0]));
}
// ...
if(AllEqual(x, y, z)) { ... }