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

submitted by HoolieManHoolieMan(1715) 4 years, 3 months 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: 13

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(4063) 4 years, 3 months ago 0

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.

Reply

posted by HoolieManHoolieMan(1715) 4 years, 3 months ago 0

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.

Reply

posted by senfosenfo(881) 4 years, 3 months ago 0

Interesting. I smell an FxCop rule coming.

Reply

posted by TweeZzTweeZz(77) 4 years, 3 months ago 0

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

Reply

posted by yesthatmcgurkyesthatmcgurk(4063) 4 years, 3 months ago 0

see the first comment, tweezz.

Reply

information Login or create an account to comment on this story