473,395 Members | 1,653 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,395 software developers and data experts.

Combined Enums / [Flags]

Im using C#3.0 and in my book of words it tells me that when I use the
[Flags] I should be able to call ToString() on a combined enumeration and
have it emit a series of strings.

IE

[Flags]
public enum myEnum
{

left =1,
right=2,
leftright = left | right

}

console.write ( myEnum.toString() ) // I Get LeftRight, when my book says I
should get "left, right"

Is the book incorrect ?

Cheers
Jun 27 '08 #1
2 1460
"Rain" <me@myplace.comwrote:
Is the book incorrect ?
No. In your example, "left | right" and "leftright" have identical
numeric values, so it picks the one that has a name in the enum. If the
combination with | operator doesn't (numerically) equal a value in the
enum, you will get the comma-separated string you mentioned instead.

Eq.
Jun 27 '08 #2
Ahhh.

So simple, yet I didnt spot it.
Thank you.
"Paul E Collins" <fi******************@CL4.orgwrote in message
news:Vu******************************@bt.com...
"Rain" <me@myplace.comwrote:
>Is the book incorrect ?

No. In your example, "left | right" and "leftright" have identical numeric
values, so it picks the one that has a name in the enum. If the
combination with | operator doesn't (numerically) equal a value in the
enum, you will get the comma-separated string you mentioned instead.

Eq.


Jun 27 '08 #3

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

Similar topics

13
by: SpaceCowboy | last post by:
I recently got into a discussion with a co-worker about using enums across a dll interface. He wanted to use chars instead, argueing that depending on compiler settings the size of an enum could...
2
by: Faisal | last post by:
Can anyone tell me if it is possible to enumerate through all the Enums within a class . I have a class with many Enums and would like to accees the Enums through an array/collection etc. I can't...
1
by: Rajesh Abraham | last post by:
I am running loop with calls different functions such as SetHomeDrive, AddUserToGroup etc. Now if any of the functions fails, I am just catching and throwing a new error like throw new...
3
by: Mike Scott | last post by:
What is the best way to index an array by an enum. Pascal has a nice feature in that arrays can be indexed by an enum, for example type ButtonType = ( Left, Middle, Right ) ; var buttons :...
2
by: Kyle Novak | last post by:
What I want to do is take the values of an enum and have a related textual description for each item. For example, if I have an enum declared as the following... public enum EqualityOperator...
4
by: Martin Pritchard | last post by:
Hi, I'm working on a project that historically contains around 40 enums. In the database various fields refer to the int values of these enums, but of course ref integrity is not enofrced and...
5
by: DMitchell | last post by:
Is there any way of getting a public enumeration to be generated into a web service proxy?
9
by: userblue | last post by:
Hi Does anyone know if there is a way to define what is effectively a single globally visible, enumerated list whilst actually defining the entries across several different modules? or somehow do...
3
by: J055 | last post by:
Hi The function below accepts an Enum value 'AccountRoles' and should return an array of Permissions which is also an Enum. When the AccountRoles is AccountRoles.Administrator it should always...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
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...

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.