in set operator for enumerated types?

  • Thread starter Thread starter Simon Storr
  • Start date Start date
S

Simon Storr

Posting this again as it just got deleted off the server?!

Is it possible to perform an 'in' set operator check on an enumerated type?
For example something like

enum WeekDays = {Mon,Tue,Wed,Thu,Fri,Sat,Sun};
WeekDays aWeekDay;
..
..
..
if (aWeekDay in {Sat,Sun}) // <-- can't find a way of doing this?
{
HurrahItsTheWeekend();
}

rather than

if ((aWeekDay == Sat)||(aWeekDay == Sun))
{
HurrahItsTheWeekend();
}

Can't find anything on set operators for C# :o(

TIA!

Simon
 
Simon Storr said:
Posting this again as it just got deleted off the server?!

No, you just didn't wait long enough.
Is it possible to perform an 'in' set operator check on an enumerated type?
For example something like

enum WeekDays = {Mon,Tue,Wed,Thu,Fri,Sat,Sun};
WeekDays aWeekDay;
.
.
.
if (aWeekDay in {Sat,Sun}) // <-- can't find a way of doing this?
{
HurrahItsTheWeekend();
}

rather than

if ((aWeekDay == Sat)||(aWeekDay == Sun))
{
HurrahItsTheWeekend();
}

Can't find anything on set operators for C# :o(

You could create a list or an array of the appropriate type, and use
IndexOf - that's the easiest way I can think of, to be honest. There's
no particularly clean syntax for it - I don't think your above
comparison would even work, as it would require WeekDays.Sat and
WeekDays.Sun.
 
Its weird - it did briefly appear then disappeared when I clicked on it -
maybe a prob with my newsreader. Never had it happen before. Apologies if
peeps are seeing multiple posts (my repost seems to have stayed put though
:o)

Simon
 
Back
Top