in set operator for enumerated types?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Simon Storr

    #1

    in set operator for enumerated types?

    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,Th u,Fri,Sat,Sun};
    WeekDays aWeekDay;
    ..
    ..
    ..
    if (aWeekDay in {Sat,Sun}) // <-- can't find a way of doing this?
    {
    HurrahItsTheWee kend();
    }

    rather than

    if ((aWeekDay == Sat)||(aWeekDay == Sun))
    {
    HurrahItsTheWee kend();
    }

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

    TIA!

    Simon



  • Jon Skeet

    #2
    Re: in set operator for enumerated types?

    Simon Storr <sstorr@sdasolu tions.com> wrote:[color=blue]
    > Posting this again as it just got deleted off the server?![/color]

    No, you just didn't wait long enough.
    [color=blue]
    > Is it possible to perform an 'in' set operator check on an enumerated type?
    > For example something like
    >
    > enum WeekDays = {Mon,Tue,Wed,Th u,Fri,Sat,Sun};
    > WeekDays aWeekDay;
    > .
    > .
    > .
    > if (aWeekDay in {Sat,Sun}) // <-- can't find a way of doing this?
    > {
    > HurrahItsTheWee kend();
    > }
    >
    > rather than
    >
    > if ((aWeekDay == Sat)||(aWeekDay == Sun))
    > {
    > HurrahItsTheWee kend();
    > }
    >
    > Can't find anything on set operators for C# :o([/color]

    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.

    --
    Jon Skeet - <skeet@pobox.co m>
    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

    If replying to the group, please do not mail me too

    Comment

    • Simon Storr

      #3
      Re: in set operator for enumerated types?

      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

      "Jon Skeet" <skeet@pobox.co m> wrote in message
      news:MPG.198082 1d3a9a4aad98a12 9@news.microsof t.com...[color=blue]
      > Simon Storr <sstorr@sdasolu tions.com> wrote:[color=green]
      > > Posting this again as it just got deleted off the server?![/color]
      >
      > No, you just didn't wait long enough.
      >[color=green]
      > > Is it possible to perform an 'in' set operator check on an enumerated[/color][/color]
      type?[color=blue][color=green]
      > > For example something like
      > >
      > > enum WeekDays = {Mon,Tue,Wed,Th u,Fri,Sat,Sun};
      > > WeekDays aWeekDay;
      > > .
      > > .
      > > .
      > > if (aWeekDay in {Sat,Sun}) // <-- can't find a way of doing this?
      > > {
      > > HurrahItsTheWee kend();
      > > }
      > >
      > > rather than
      > >
      > > if ((aWeekDay == Sat)||(aWeekDay == Sun))
      > > {
      > > HurrahItsTheWee kend();
      > > }
      > >
      > > Can't find anything on set operators for C# :o([/color]
      >
      > 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.
      >
      > --
      > Jon Skeet - <skeet@pobox.co m>
      > http://www.pobox.com/~skeet/
      > If replying to the group, please do not mail me too[/color]


      Comment

      Working...