Something you probably don't know about enums in C# (blog.spontaneouspublicity.com)

published 2 years ago, submitted by HoolieManHoolieMan(1680) 2 years ago

Do you think the use of an enum in your code is limiting the possible values that can be used? Think again. Maybe we need to learn to be more careful about checking our enums for valid values.

5 comments | category: | Views: 7

tags: another

new Add a live kick counter to your blog >> liveImage

You can even customize the image by choosing your own colors, and then clicking the button below to update the preview and the html code:

  • "Kick It" text
  • "Kick It" background
  • kick count text
  • kick count background
  • border

Simply copy and paste this HTML into your blog post.


Users who kicked this story:

Comments:

posted by yesthatmcgurkyesthatmcgurk(3805) 2 years ago

I'm 99% sure its this way so that you can logical-OR together enum values and store the result with a variable of the enum's type.

posted by HoolieManHoolieMan(1680) 2 years ago

Yeah, the logical-OR scenario seems like the best explanation. It would be nice if they limited this behavior only to enums with the [Flags] attribute just to make things clearer for enums which are not meant to be OR'd together.

posted by senfosenfo(870) 2 years ago

Interesting. I smell an FxCop rule coming.

posted by TweeZzTweeZz(75) 2 years ago

I was googling a bit. Do you know the 'FlagsAttribute' that you can put on top of an enum defenition?
http://msdn2.microsoft.com/en-us/library/system.flagsattribute.aspx

posted by yesthatmcgurkyesthatmcgurk(3805) 1 year, 11 months ago

see the first comment, tweezz.

information Login or create an account to comment on this story