tags:

views:

362

answers:

3

Take the following code for example;

    if (Convert.ToString(frm.WindowState) == "Minimized")
        Layout.WindowState = "Maximized";
    else
        Layout.WindowState = Convert.ToString(frm.WindowState);

We are analysing the string definition of the window state, i.e. "Minimized".

Would this string description change between cultures?

Lastly, whilst on this code, is there an Enum which we could use in order to check against the window state?

Can we refactor this code segment?

+8  A: 

The WindowState value is an enumeration - System.Windows.Forms.FormWindowState. Just compare to the enumeration constants, skip the ToString() madness.

Shog9
Thanks, we will adopt your suggestions and do away with the .ToString() mumbo jumbo.
Helios
A: 

WindowState is an enumeration.

I suggest using a good IDE (Visual Studio f.e) which will make similar details obvious.

System.Windows.WindowState

arul
+1  A: 

It shouldn't change across culture, since it's merely turning the Enum name into string. Enum name doesn't change when you use different culture of .Net/Windows/IDE, thus it will remain as what it was originally written.

faulty