Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7514651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:33:44+00:00 2026-05-30T00:33:44+00:00

Did you ever have a day when nothing works? Now I can’t even succeed

  • 0

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!

Debugger Snap:

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T00:33:47+00:00Added an answer on May 30, 2026 at 12:33 am

    try removing the false operator –

    BitmapCacheOption bitmapCacheOption1 =
                (BitmapCacheOption)Enum.Parse(typeof(BitmapCacheOption), x);
    

    And on the way – Upload the Enum structure for us to see if there is a problem.

    edit:wow !

    enter image description here

    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….

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Did you ever have the following situation: you need to store information, but a
Does (or did) Twitter ever have a method in their API that allowed client-side
Did you ever have to persuade your customers that migrating your ASP.NET web forms
Did you ever have to choose between WISA or LAMP at the beginning of
Why did programmers ever start using status codes? I mean, I guess I could
Did not have luck with these examples: Javascript File remove Javascript FSO DeleteFile Method
I have a Silverlight 5 application with a bunch of methods having a signature
I followed some steps I found here (can't find the URL right now, sorry)
Did anybody ever installed wkhtmltopdf on Fedora 14? On http://code.google.com/p/wkhtmltopdf/wiki/compilation there is a step
When you were a kid, did you ever ask your parents how to spell

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.