473,386 Members | 2,114 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,386 software developers and data experts.

Enum

Hello,

I have the following Enum

Public Enum Mode
Required
Validate
End Enum

How can I make a variable of type Mode to hold both Required and
Validate values without needing to add an option to my enum named
RequiredValidate?

And how can I check if that variable contains Required, Validate or
Required and Validate?

Is this possible?

Thanks,

Miguel

Oct 31 '07 #1
4 1822
You can't.

An enum is logically the same as an Integer. So trying to store both
Required and Validate in a variable declared as Mode is like trying to
store a zero and a one in an Integer that will only hold a zero or a
one. (or a one and a two)

You are going to need a third item in the Enum.

-----Original Message-----
From: shapper [mailto:md*****@gmail.com]
Posted At: Wednesday, October 31, 2007 7:42 AM
Posted To: microsoft.public.dotnet.framework.aspnet
Conversation: Enum
Subject: Enum

Hello,

I have the following Enum

Public Enum Mode
Required
Validate
End Enum

How can I make a variable of type Mode to hold both Required and
Validate values without needing to add an option to my enum named
RequiredValidate?

And how can I check if that variable contains Required, Validate or
Required and Validate?

Is this possible?

Thanks,

Miguel

Oct 31 '07 #2
MyMode=Mode.Required Or Mode.Validate is perfectly valid

If you want to create a value that combine both you'll have to add this
value to your enum as RequiredValidate=Required Or Validate

Each value is a power of two so that you can combine values into a single
value (using or) or test them (using and).

See
http://msdn2.microsoft.com/en-us/lib...te(VS.80).aspx
for details...

--
Patrice

"Dave Bush" <da*******@dmbcllc.coma écrit dans le message de news:
47F6BFDC9EAD43F4A5F9229ABA619EBB@OfficeVista...
You can't.

An enum is logically the same as an Integer. So trying to store both
Required and Validate in a variable declared as Mode is like trying to
store a zero and a one in an Integer that will only hold a zero or a
one. (or a one and a two)

You are going to need a third item in the Enum.

-----Original Message-----
From: shapper [mailto:md*****@gmail.com]
Posted At: Wednesday, October 31, 2007 7:42 AM
Posted To: microsoft.public.dotnet.framework.aspnet
Conversation: Enum
Subject: Enum

Hello,

I have the following Enum

Public Enum Mode
Required
Validate
End Enum

How can I make a variable of type Mode to hold both Required and
Validate values without needing to add an option to my enum named
RequiredValidate?

And how can I check if that variable contains Required, Validate or
Required and Validate?

Is this possible?

Thanks,

Miguel

Oct 31 '07 #3
You need to add the Flags attribute to the enum. You should set each value
specifically to be the value of a single bit (i.e. 1, 2, 4, 8, 16, etc...).
This way you can tell which enum flag is in a value. If you have the value
of 5 that means you have the enum values of 1 and 4.

Your example is below:

<Flags_
Public Enum Mode
Required = 1
Validate = 2
End Enum


"shapper" <md*****@gmail.comwrote in message
news:11**********************@57g2000hsv.googlegro ups.com...
Hello,

I have the following Enum

Public Enum Mode
Required
Validate
End Enum

How can I make a variable of type Mode to hold both Required and
Validate values without needing to add an option to my enum named
RequiredValidate?

And how can I check if that variable contains Required, Validate or
Required and Validate?

Is this possible?

Thanks,

Miguel

Oct 31 '07 #4
On Wed, 31 Oct 2007 13:10:14 +0100, "Patrice"
<http://www.chez.com/scribe/wrote:
>MyMode=Mode.Required Or Mode.Validate is perfectly valid

If you want to create a value that combine both you'll have to add this
value to your enum as RequiredValidate=Required Or Validate

Each value is a power of two so that you can combine values into a single
value (using or) or test them (using and).

See
http://msdn2.microsoft.com/en-us/lib...te(VS.80).aspx
for details...
To do this, add a <Flags()attribute before the enum

--
http://bytes.thinkersroom.com
Nov 1 '07 #5

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

Similar topics

20
by: Glenn Venzke | last post by:
I'm writing a class with a method that will accept 1 of 3 items listed in an enum. Is it possible to pass the item name without the enum name in your calling statement? EXAMPLE: public enum...
21
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 {
31
by: Michael C | last post by:
If a class inherits from another class, say Form inherits from control, then I can assign the Form to a variable of type Control without needing an explicit conversion, eg Form1 f = new Form1();...
18
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
2
by: Dennis | last post by:
I have an enum as follows: Public Enum myData FirstData = 6 SecondData = 7 end enum Is there anyway that I can return the Enum names by their value, i.e., I want to input 6 into a function...
13
by: Don | last post by:
How do I get an Enum's type using only the Enum name? e.g. Dim enumType as System.Type Dim enumName as String = "MyEnum" enumType = ???(enumName)
10
by: Randy | last post by:
Hi, Can anyone point me to a complete, compilable example of Besser's ENUM++ mechanism? I downloaded it from CUJ and gave it a try but got errors just trying to compile the header enum.h. ...
1
by: Randy | last post by:
Hi, I downloaded and tried the ENUM++ code from CUJ http://www.cuj.com/documents/s=8470/cujboost0306besser/ but can't even get it to compile (see following). I have also downloaded and...
2
by: Randy | last post by:
Hi, I downloaded and tried the ENUM++ code from CUJ http://www.cuj.com/documents/s=8470/cujboost0306besser/ but can't even get it to compile (see following). I have also downloaded and...
34
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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...
0
Oralloy
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 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.