473,324 Members | 2,166 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

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,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

Nov 13 '05 #1
2 3332
Simon Storr <ss****@sdasolutions.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Nov 13 '05 #2
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" <sk***@pobox.com> wrote in message
news:MP************************@news.microsoft.com ...
Simon Storr <ss****@sdasolutions.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too

Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Brandon | last post by:
Hello all, and thanks for taking a look at this. First off, the project I am working on is a server/client application that contains a shared assembly of common classes between the two...
2
by: Daniel Wilson | last post by:
I have an enumerated type like this: public __value enum MyType{ ABC = 1, DEF = 2, GHI = 3, JKL = 4 }; Later I have a for loop like this: for (ft = MyType::ABC; ft <= MyType::JKL; ft++){
22
by: Ben Finney | last post by:
Howdy all, I've recently packaged 'enum' in PyPI. In its description, I make the claim that it creates "immutable" enumeration objects, and that the enumeration values are "constant" values. ...
6
by: TuxC0d3 | last post by:
Hi! I'm diving into the some more ++ specific aspects of c++ (and finally accepting that c++ is more than "a plus added to c" :), so that means using namespaces, templates, std::strings, lists,...
4
by: Shawnk | last post by:
This post is intended to verify that true value semantics DO NOT EXIST for the Enum class (relative to boolean operations). If this is true then (thus and therefore) you can not design state...
7
by: John Goche | last post by:
Hello, The following program compiler and runs fine under gcc and produces the output 3. However, I am not sure whether such behavior is legal. In particular, as a related question, how would I...
11
by: Zilla | last post by:
I have the following simple program. I just want to be able to do math operations (+, -, =)on Timer sublcasses, but want to handle cases where either rhs or lhs is an intrinsic value, However, the...
2
by: Bharath | last post by:
Hello All, Can you please let me know if we can do pointer arthrmetic using operator overloading? If not, can you please explain why it's not supported by compiler? I tried below e.g. which was...
7
by: Bill Davy | last post by:
I want to be able to write (const char*)v where v is an item of type Class::ToolTypeT where ToolTypeT is an enumeration and I've tried everything that looks sensible. There's an ugly solution, but...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.