Did you ever have a day when nothing works? Now I can’t even succeed in setting the value of an enum!
I was having trouble with the Enum.Parse statement at the bottom, so I’ve written the ‘if’ block above it. To my surprise, this also failed.
I traced this with the debugger. The value of the string x is “OnDemand”. The first ‘if”s “true” branch is taken, but bitmapCacheOption stays BitmapCacheOption.Default.
Ditto for the Enum.Parse expression below. So my question is: What am I doing wrong in assigning value to an enum?
BitmapCacheOption bitmapCacheOption;
if (x == "OnDemand") bitmapCacheOption = BitmapCacheOption.OnDemand;
else
{
if (x == "OnLoad") bitmapCacheOption = BitmapCacheOption.OnLoad;
else
{
if (x == "None") bitmapCacheOption = BitmapCacheOption.None;
else bitmapCacheOption = BitmapCacheOption.Default;
}
}
BitmapCacheOption bitmapCacheOption1 =
(BitmapCacheOption)Enum.Parse(typeof(BitmapCacheOption), x, false);
Debug.Assert(bitmapCacheOption == bitmapCacheOption1);
Edit: The enum in quesion is a WPF one, BitmapCacheOption. The false at the end of the Enum.Parse statement just means to ignore the case. I’m aware of better ways to write a cascading ‘if’ statement (including “else if” and “switch” statements), but all this is beside the issue. I’ve written the ‘if’ this way during debugging to allow me to step through with the debugger. What is important is that even with the simple if, when x equals “OnDemand” bitmapCacheOption stays BitmapCacheOption.Default!
edit: Notice the value of “bitmapCacheOption” in the Debugger’s Locals window – it stays in “Default” even though the yellow highlight displays that the “OnDemand” swithc case wast taken!

try removing the false operator –
And on the way – Upload the Enum structure for us to see if there is a problem.
edit:wow !
it looks like they have a bug – both index with 0.
This is why you get the default every time. because it is 0. its fine … but when you set the value to x – it assigns him the 0 instead anothe YYY value which should be there….