Results 1 to 7 of 7

Thread: Case with && Error!

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    Case with && Error!

    hi,

    Im getting an error on the case lines in Red:
    ========================================
    Cannot implicitly convert type 'bool' to 'int'
    ========================================
    Any help please. Thanks

    Code:
     switch (total)
                {     case (total < 50):                    
                       grade = "FAIL";
    
                    case (total >= 50 && total < 70):                
                      grade = "PASS";
    
                        case (total > 70 && total < 80):
                        grade = "MERIT";
    
                       case  (total >= 80 && total < 90):        
                       grade = "DISTINCTION";
    ------------------------------------------------------------------------
    If an answer to your question has been helpful, then please, Rate it!

  2. #2
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Case with && Error!

    Hello,

    I do not believe that this is possible in the C# Specification.

    http://msdn.microsoft.com/en-us/libr...7t(VS.71).aspx

    I believe you will have to do this using If's.

    Hope this helps!!

    Gary

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2004
    Location
    in the heart of the Mediterranean
    Posts
    1,143

    Re: Case with && Error!

    Still get the same error even with an if ... else if statements. So it seems something is wrong in the logical expression.
    Last edited by angelica; Feb 23rd, 2009 at 04:48 PM.
    ------------------------------------------------------------------------
    If an answer to your question has been helpful, then please, Rate it!

  4. #4
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Case with && Error!

    Hey,

    I certainly wouldn't call it weak.

    This seems to be possible in VB:

    http://www.java2s.com/Tutorial/VB/00...tegervalue.htm

    But not so in C#. I am sure there is a very good reason to this, but I don't know what that reason is.

    Gary

  5. #5
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Case with && Error!

    Try an additional set of parenthesis:
    Code:
    ((total >= 50) && (total < 70)):
    Make sure you know exactly what order things are processing in.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Case with && Error!

    Hey,

    Techgnome, I don't think that is going to help.

    When I attempted to convert the code in the link that i posted I got the following error:

    "Case labels with binary operators are unsupported"

    Therefore, I simply think that this case statement functionality is not supported in the C# language specification.

    Gary

  7. #7
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: Case with && Error!

    Try turning on Option Strict in VB, then even it will expect Constant expressions in CASE and Ranged integral values will throw error.

    @OP, you are pretty much out of luck here. You have to use IF-THEN-ELSEIF conditions in your case.
    Show Appreciation. Rate Posts.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width