How to encode a switch statement to test DialogResult and ensure logic drops

I get strange results checking the return value from a function. This code is inside the for loop:

DialogResult result = EvalReturnFromWS(returnMsg);
     switch (result)
     {
         case DialogResult.Yes:
         case DialogResult.No:
              continue;
         default:
              break;
     } 

Here is a snippet from the function being called (in my unit testing, I always press the yes button):

DialogResult result = MessageBox.Show(mbText.ToString(), caption, button, icon);
switch (result)
    {
         case DialogResult.Yes:
              return DialogResult.Yes;
         case DialogResult.No:
              return DialogResult.No;
         case DialogResult.Cancel:
              return DialogResult.Cancel;
    }

When I click “Yes”, it returns DialogResult.Yes, but back in the calling code, executing the thread in the second case, which is “no”, and this continues, which I DO NOT intend.

Elsewhere in StackOverflow, I saw a stream offering to encode a "failure", for example, for DialogResult. Yes, it can fail.

In short, if YES, I want to resume execution with the next operation after the end (s) of the switch. That is, "fails."

- . , for. ( MessageBox.Show).

+3
2

, , break; DialogResult.Yes. , .

 switch (result)
 {
     case DialogResult.Yes:
          break; //Leaves the switch statement and continues executing code
     case DialogResult.No:
          continue; //Moves to next iteration of loop
     default:
          break; //Leaves the switch statement and continues executing code
 }

, case . , switch. break; default: (, ) switch. , . , break; , case switch. continue; , .

:

for (int i = 0; i < 3; i++) {
    switch (i) {
        case 0:
        case 2:
            continue;
        default:
            break;
    }
    Console.Out.WriteLine(i);
}

1, i=0 i=2 . i=1 Console.Out.WriteLine(i);.

Edit
, , . :

+8

? , , "" №. , , . , "" " " ,

case DialogResult.Yes:
    break;
0

All Articles