Click here to Skip to main content
14,271,339 members
Rate this:
Please Sign up or sign in to vote.

I use the following code:
namespace wpfEmun
    enum Seizoen { lente , zomer, herfst, winter, autumn = herfst, spring = lente, summer = zomer };

    public partial class Form1 : Form
        public Form1()

        private void button1_Click(object sender, EventArgs e)
            Seizoen seizoen = Seizoen.autumn;
            int seizoengetal = (int)seizoen;
            MessageBox.Show(string.Format("Seizoen nr {0} is {1}", seizoengetal, seizoen .ToString()));


If I debug and add a watch to seizoen then I see "herfst", and the result is ok.
BUT, in the message box the text "autumn" is displayed.
So in short: var seizoen contains "herfst" but shows "autumn" and it should be "herfst".

Updated 5-Apr-14 8:04am
Bernhard Hiller 7-Apr-14 2:56am
If you are just interesetd in showing a "readable" value for your enum, look at a trick which uses a Description attribute for each enum value. If you need globalization/localization support, you can use the attribute for providing the name of the localized resource instead.
Rate this:
Please Sign up or sign in to vote.

Solution 2

This is the perfectly expected result. I described the phenomenon you observed in detail in my article where I also created some interesting work-around solution: Enumeration Types do not Enumerate! Working around .NET and Language Limitations.

Rate this:
Please Sign up or sign in to vote.

Solution 1

You should try it the other way around: now you do English word = Dutch word, but you should do Dutch word = English word:
enum Seizoen { spring, summer, autumn, winter, lente = spring, zomer = summer, herfst = autumn };

First, add the English words to the enum and then add the Dutch words to it.
Alex Houben 5-Apr-14 16:53pm
Hi ProgramFOX,

Unfortunately this gives me 2 errors:
1) Cannot implicitly convert type 'wpfEmun.Form1.Seizoen' to 'int'. An explicit conversion exists (are you missing a cast?)
2) The evaluation of the constant value for 'wpfEmun.Form1.Seizoen.lente' involves a circular definition.

BTW I tested it on VS2008 & VS2012 but they give both the same result.
Thomas Daniels 6-Apr-14 4:05am
I updated my answer. I was wrong about the order of items in the enum.
This is not a solution. The problem is quite non-trivial. Please see my answer where I refer to my detailed article on this problem (the article is about the fact that enum types don't support IEnumerable interface, but big part is devoted to this very problem).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100