All Questions

1033
votes
10answers
333021 views

What does the [Flags] Enum Attribute mean in C#?

From time to time I see an enum like the following: [Flags] public enum Options { None = 0, Option1 = 1, Option2 = 2, Option3 = 4, Option4 = 8 } I don't understand what exac...
1146
votes
43answers
591745 views

How can I represent an 'Enum' in Python?

I'm mainly a C# developer, but I'm currently working on a project in Python. How can I represent the equivalent of an Enum in Python?
875
votes
17answers
242356 views

Create Generic method constraining T to an Enum

I'm building a function to extend the Enum.Parse concept that Allows a default value to be parsed in case that an Enum value is not found Is case insensitive So I wrote the following: public stat...
1461
votes
23answers
778766 views

Lookup enum by string value

Say I have an enum which is just public enum Blah { A, B, C, D } and I would like to find the enum value of a string, for example "A" which would be Blah.A. How would it be possible to do this?...
491
votes
19answers
366934 views

How should I convert a string to an enum in C#?

What's the best way to convert a string to an enumeration value in C#? I have an HTML select tag containing the values of an enumeration. When the page is posted, I want to pick up the value (which w...
788
votes
32answers
632108 views

C# String enums

I have the following enumeration: public enum AuthenticationMethod { FORMS = 1, WINDOWSAUTHENTICATION = 2, SINGLESIGNON = 3 } The problem however is that I need the word "FORMS" when I ...
2353
votes
21answers
918340 views

Cast int to enum in C#

How can an int be cast to an enum in C#?
2911
votes
26answers
556701 views

How do I enumerate an enum?

How can you enumerate an enum in C#? E.g. the following code does not compile: public enum Suit { Spades, Hearts, Clubs, Diamonds } public void EnumerateAllSuitsDemoMethod() { ...
344
votes
18answers
211958 views

Getting attributes of Enum's value

I would like to know if it is possible to get attributes of the enum values and not of the enum itself? For example, suppose I have the following enum: using System.ComponentModel; // for Description...
341
votes
8answers
106747 views

How to bind RadioButtons to an enum?

I've got an enum like this: public enum MyLovelyEnum { FirstSelection, TheOtherSelection, YetAnotherOne }; I got a property in my DataContext: public MyLovelyEnum VeryLovelyEnum { get; set; ...

Previous Next