[.net] need c# shortcut
Hey, I'm writing a quiz (multipul choice) and going to test a person who tests my progrms for bugs and unhandled exeptions. what i am going to do is make "a" and "b" both correct. I was wondering if there was a way to say instead of the if statement for one answer i want it to do both if they type A or B
thanks
cyro393
use a switch statement.
switch(variable){
case 'A':
//code here
break;
case 'B':
//code here
break;
}
Hope that helps
switch(variable){
case 'A':
//code here
break;
case 'B':
//code here
break;
}
Hope that helps
Quote:Original post by Jedite
use a switch statement.
switch(variable){
case 'A':
//code here
break;
case 'B':
//code here
break;
}
Hope that helps
If I interpeted his problem correctly, if he used a switch statement he'd probably want it to fall through.
switch(variable){case 'A':case 'B': //code here break;}
C# does not support an explicit fall through from one case label to another.
Therefor the correct code would be:
Therefor the correct code would be:
switch(variable){case 'A': goto case 'B';case 'B': //code here break;}
Nice.
Buttotally wrong.
Iunteresting how people post bullshit without reading the doc.
C' does support muldiple case statementson one code block. The goto is a sign you do not know C#.
Buttotally wrong.
Iunteresting how people post bullshit without reading the doc.
C' does support muldiple case statementson one code block. The goto is a sign you do not know C#.
Quote:Original post by ekampf
C# does not support an explicit fall through from one case label to another.
Therefor the correct code would be:
*** Source Snippet Removed ***
Explicit fall-throughs are only necessary when the first case is not empty.
switch(variable){case 'A':SomeStatement();goto case 'B'; //case 'A' isn't empty so we need explicit fall-throughcase 'B':SomeOtherStatement();break;}
If case A is empty and you just wanted it to fall through (ie: the example in my first post in this thread) the goto wouldn't be necessary.
Skipping back to the original question I think a better design would be:
This way the debug version will allow all answers to be correct but the Release version will not. You could even create a special Testing configuration.
Cheers
[Edited by - ernow on August 18, 2004 1:57:29 AM]
#if !DEBUGif(answer == correct)#endif{ ...}
This way the debug version will allow all answers to be correct but the Release version will not. You could even create a special Testing configuration.
Cheers
[Edited by - ernow on August 18, 2004 1:57:29 AM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement