C# MessageBox dialog result

前端 未结 5 1228
心在旅途
心在旅途 2021-01-30 04:17

I want to make a MessageBox confirmation. Here is the message box:

MessageBox.Show(\"Do you want to save changes?\", \"Confirmation\", messageBoxButtons.YesNoCan         


        
5条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-30 04:40

    Rather than using if statements might I suggest using a switch instead, I try to avoid using if statements when possible.

    var result = MessageBox.Show(@"Do you want to save the changes?", "Confirmation", MessageBoxButtons.YesNoCancel);
    switch (result)
    {
        case DialogResult.Yes:
            SaveChanges();
            break;
        case DialogResult.No:
            Rollback();
            break;
        default:
            break;
    }
    

提交回复
热议问题