[.net] need c# shortcut

Started by
7 comments, last by ernow 19 years, 8 months ago
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
Advertisement
if(a == rawr || b == yawn) ...

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.

use a switch statement.

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;}
yeah i wasnt sure if he wanted that or just something other than if statements to use
C# does not support an explicit fall through from one case label to another.
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#.
RegardsThomas TomiczekTHONA Consulting Ltd.(Microsoft MVP C#/.NET)
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:
#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