473,813 Members | 3,808 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1474
"Rain" <me@myplace.com wrote:
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.orgw rote in message
news:Vu******** *************** *******@bt.com. ..
"Rain" <me@myplace.com wrote:
>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
9559
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 change and lead to memory corruption. I didn't see how this was possible. He claims that if a dll built for a program is built with different compiler settings than the launcher program, the enum size could change. The only way I could figure...
2
2083
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 seem to find an appropriate Reflection method to access Enums within a class I would like to loop through the Enums in the 'Foo' Class retrieve the Enums 'Car' and 'House Public Class Fo Public Enum Ca For Chevrole Toyot
1
4202
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 Exception("Failed to Set Home Drive") etc. All these errors which are propelled back to my loop are then logged to file. Even if an error occours in one ore more function, the loop continues execution so I deally I would like to have unique flag for...
3
14732
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 : array of Button ; ....
2
2499
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 { Equal = 1, LessThan = 2, GreaterThan = 4,
4
5595
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 when looking at the db we can't tell what the value in a field represents. The other problem is that our enums are currently all stored in a single class, which means that because of no visibility constraints the enums are often used out of context...
5
12537
by: DMitchell | last post by:
Is there any way of getting a public enumeration to be generated into a web service proxy?
9
2790
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 a similar thing with macros. Details: I have a c project to fit into a small microprocessor and need to save some ram. I have a significant number of flags all over the place that currently use whole byte storage. I thought if I had a way to...
3
1716
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 return the full list of values from the Permissions enum. Is there a clean way to do this? public static Permissions GetPermissions(AccountRoles role) {
0
10407
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10422
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10139
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9222
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6897
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5705
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4358
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3885
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3030
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.