simple question :-
i have the following simple if (..) statements :-
if (foo == Animal.Cat || foo == Animal.Dog)
{ .. }
if (baa == 1|| baa == 69)
{ .. }
is it possible to refactor these into something like …
DISCLAIMER: I know this doesn’t compile .. but this is sorta what i’m trying to get…
if (foo == (Animal.Cat || Animal.Dog))
{ .. }
if (baa == (1 || 69))
{ .. }
Cheers 🙂
EDIT
I wonder if a lambda expression extension could do this? 😛
I usually create an extension method called
IsIn()that takes a generic parameter array of type<T>and then calls.Contains()on it, passing the instance on which the extension is called.It looks like
if (foo.IsIn(foo1, foo2)). Very simple to write, super easy to use.