Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with switch statment

Status
Not open for further replies.

DotNetBlocks

Programmer
Apr 29, 2004
161
US
Hello,

I am new to C#, but I have exp in VB.net. I am having an issue with a case/switch statment in C#, and can not seem to figure out why.

Every case statment receives the following error:
"A constant value is expected"


Shouldn't this always resolve to True or False?
(determine < 0) = T or F

Code:
  bool n = true;
            switch (n)
            {
                case (determine < 0):
                    {
                        GuessMessageResponse(-1);
                        return GuessNumber(hidden);
                    }
                case (determine > 100):
                    {
                        GuessMessageResponse(1);
                        return GuessNumber(hidden);
                    }
                case (determine < 0):
                    {
                        GuessMessageResponse(-1);
                      return GuessNumber(hidden);
                    }
                 case (determine - hidden) > 0:
                    {
                        GuessMessageResponse(1);
                      return GuessNumber(hidden);
                     }
                  default:
                  {
                      GuessMessageResponse(0);
                   return hidden;
                  }
            }

Babloome
 
In case your interested, this thread spawned an interesting discussion on switch statements (particularly how you can avoid using them). thread732-1454140

[small]----signature below----[/small]
Majority rule don't work in mental institutions

My Crummy Web Page
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top