Sign in to follow this  

[.net] need c# shortcut

This topic is 4871 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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;
}

Share this post


Link to post
Share on other sites
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;
}


Share this post


Link to post
Share on other sites
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#.

Share this post


Link to post
Share on other sites
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-through
case '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.

Share this post


Link to post
Share on other sites
Skipping back to the original question I think a better design would be:


#if !DEBUG

if(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]

Share this post


Link to post
Share on other sites

This topic is 4871 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this