I want to make a MessageBox confirmation. Here is the message box:
MessageBox.Show("Do you want to save changes?", "Confirmation", messageBoxButtons.YesNoCancel);
And I want to make something like this (in pseudocode):
if (MessageBox.Result == DialogResult.Yes)
;
else if (MessageBox.Result == DialogResult.No)
;
else
;
How can I do that in C#?
This answer was not working for me so I went on to MSDN. There I found that now the code should look like this:
Hope it helps
You can also do it in one row:
And if you want to show a messagebox on top:
If you're using WPF and the previous answers don't help, you can retrieve the result using:
Rather than using if statements might I suggest using a switch instead, I try to avoid using if statements when possible.