c# - Compare multiple values in one condition -


this question has answer here:

int32 int1, int2, int3 = 123; 

given above variables, how can test of variables have value 123 without creating collection perform any or on?

what i've tried

if(int1 == int2 == int3 == 123) {    // fantastic code here } 

edit

i must apologise, haven't been clear enough in question. i'm aware of && operator, asking regard 'elegance', i.e. how can avoid repeating value want compare against.

in same way have assigned 3 integer variables same value in 1 hit, i'd make comparison. it's looking though there no way of doing this, far. think i'm asking impossible, i'll have stick basic syntax , keep simple.

you can create usefull extension function:

public static bool equalsall<t>(this t val, params t[] values) {     return values.all(v => v.equals(val)); } 

call like:

bool res = 123.equalsall(int1,int2,int3); 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -