Hi,
To exclude users based on a criteria, I have created an enum like so:
[FlagsAttribute]
public enum Exclusions:byte
{
None=0,
HaveEmail=1,
IsAdmin=2
};
I would later like to make decisions based on the enum type setting:
Exclusions exclude = Exclusions.HaveEmail & Exclusions.IsAdmin;
switch(exclude)
{
case Exclusions.None:
//dosomething
break;
case Exclusions.HaveEmail:
//dosomething
break;
case Exclusions.IsAdmin:
//dosomething
break;
case (Exclusions.HaveEmail & Exclusions.IsAdmin): //***ERROR***
//dosomething
break;
}
When I try to handle the case where exclude=3 (HaveEmail & IsAdmin), the
compiler generates an error saying the case is already hadled.
Can someone please illuminate why this is not allowed and tell me if it's
possible to do this without puting numeric constants in my case statement?
Thank you very much,
-Keith 2 10623
Hi Keith,
You need to use bitwise OR rather then AND. with AND it will always give you
0. as long as your flags are only one bit.
The bottom line if you want to combine flags use | operator
--
HTH
Stoitcho Goutsev (100) [C# MVP]
"Keith Harris" <Ke*********@discussions.microsoft.com> wrote in message
news:2D**********************************@microsof t.com... Hi,
To exclude users based on a criteria, I have created an enum like so:
[FlagsAttribute] public enum Exclusions:byte { None=0, HaveEmail=1, IsAdmin=2 };
I would later like to make decisions based on the enum type setting:
Exclusions exclude = Exclusions.HaveEmail & Exclusions.IsAdmin;
switch(exclude) { case Exclusions.None: //dosomething break; case Exclusions.HaveEmail: //dosomething break; case Exclusions.IsAdmin: //dosomething break; case (Exclusions.HaveEmail & Exclusions.IsAdmin): //***ERROR*** //dosomething break; }
When I try to handle the case where exclude=3 (HaveEmail & IsAdmin), the compiler generates an error saying the case is already hadled.
Can someone please illuminate why this is not allowed and tell me if it's possible to do this without puting numeric constants in my case statement?
Thank you very much, -Keith
Keith Harris <Ke*********@discussions.microsoft.com> wrote in message news:<2D**********************************@microso ft.com>... Hi,
To exclude users based on a criteria, I have created an enum like so:
[FlagsAttribute] public enum Exclusions:byte { None=0, HaveEmail=1, IsAdmin=2 };
I would later like to make decisions based on the enum type setting:
Exclusions exclude = Exclusions.HaveEmail & Exclusions.IsAdmin;
switch(exclude) { case Exclusions.None: //dosomething break; case Exclusions.HaveEmail: //dosomething break; case Exclusions.IsAdmin: //dosomething break; case (Exclusions.HaveEmail & Exclusions.IsAdmin): //***ERROR*** //dosomething break; }
When I try to handle the case where exclude=3 (HaveEmail & IsAdmin), the compiler generates an error saying the case is already hadled.
Can someone please illuminate why this is not allowed and tell me if it's possible to do this without puting numeric constants in my case statement?
Thank you very much, -Keith
Remember you are using and....but you two flags are in binary 01 and
10....if you & them thats 0....you say you want 3...you need to
|...which gives 11 or 3 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: AngleWyrm |
last post by:
"The C++ Programming Language" by Bjarne Stroustrup, copyright 1997 by AT&T,
section 4.8 (pp 77):
"A value of integral type may be explicitly converted to an enumeration
type. The result of such a...
|
by: Nikhil Patel |
last post by:
Hi all,
I am a VB6 programmer and learning C#. I am currently reading a chapter
on types. I have question regarding enums. Why do we need to convert enum
members to the value that they represent?...
|
by: Matt |
last post by:
Hi,
Recently we had some code like this cause a failure:
MyEnum myEnum = (MyEnum) (int) dt;
i.e. reading an int out of the database and casting it into a
type-safe enum.
The thought...
|
by: Andreas Huber |
last post by:
Hi there
Spending half an hour searching through the archive I haven't found a
rationale for the following behavior.
using System;
// note the missing Flags attribute
enum Color
{
|
by: todorov-fkt |
last post by:
Hello everyone,
I have a field which is 1 byte long and is used to store different flags
(according to specs) - it is the flags bit in the ID3 tag header. So
0xabc00000 represents the byte,...
|
by: Simon |
last post by:
Hi all,
I think I've seen someone passing an emumeration in code before.
Can anyone tell me if thats possible and why i would want to.
Many thanks
Kindest Regards
|
by: Dwight.Dexter |
last post by:
I have an enum variable. Is there some way to cast an int or BitArray
and get my enum value? I have to communicate with an old C-style
sever so I get an array of bits("0","1"). But I'm using an...
|
by: Visual Systems AB \(Martin Arvidsson\) |
last post by:
Hi!
I have created an enum list like this:
enum myEnum : int
{
This = 2,
That,
NewVal = 10,
LastItm
|
by: Steven Nagy |
last post by:
So I was needing some extra power from my enums and implemented the
typesafe enum pattern.
And it got me to thinking... why should I EVER use standard enums?
There's now a nice little code...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |