Question:What is the issue with the following function?
public string GetName(int iValue)
{
    string sValue = "0";
    switch (iValue)
    {
        case 1:
            sValue = iValue.ToString();
        case 2:
            sValue = iValue.ToString();
            break;
        default:
            sValue = "-1";
            break;
    }
    return sValue;
}
 

A The code will not compile as there shouldn't be a break statement in the default case label. 

B The code will compile but if case 1 is passed as the input parameter to the function, the code for case 2 will also execute (after the code for case 1), and so the wrong value may be returned. 

C The code will compile and run without any issues. 

D The code will not compile as there is no break statement in case 1. 

+ Answer
+ Report
Total Preview: 711

Copyright © 2024. Powered by Intellect Software Ltd