c# - Is this big complicated thing equal to this? or this? or this? -
let's i'm working object of class thing. way i'm getting object bit wordy:
bigobjectthing.uncle.preferredinputstream.nthrelative(5) i'd see if thing equal x or y or z. naive way write might be:
bigobjectthing.uncle.preferredinputstream.nthrelative(5) == x || bigobjectthing.uncle.preferredinputstream.nthrelative(5) == y || bigobjectthing.uncle.preferredinputstream.nthrelative(5) == z in languages write this:
bigobjectthing.uncle.preferredinputstream.nthrelative(5) == x |= y |= z but c# doesn't allow that.
is there c#-idiomatic way write test as single expression?
just use variable:
var relative = bigobjectthing.uncle.preferredinputstream.nthrelative(5); return relative == x || relative == y || relative == z; or if want fancy larger set of things:
var relatives = new hashset<thing>(new[] { x, y, z }); return relatives.contains(bigobjectthing.uncle.preferredinputstream.nthrelative(5));
Comments
Post a Comment