private void button1_Click(object sender, EventArgs e)
        {
            DialogResult str = MessageBox.Show("枚举返回值","AbortRetryIgnore,终止,重试,忽略", MessageBoxButtons.AbortRetryIgnore);
            if (str.ToString() == "Abort") ;
            {
                MessageBox.Show("终止", "about");
            }
                if (str.ToString() == "Retry")
                {
                    MessageBox.Show("重试", "retry");
                }
                if (str.ToString() == "ignore")
                {
                    MessageBox.Show("忽略", "Ignore");
                }
            }
单击button后,根据返回值弹出消息框

解决方案 »

  1.   

    you can try like thisprivate void button1_Click(object sender, EventArgs e)
    {
        DialogResult result = MessageBox.Show("枚举返回值", "AbortRetryIgnore,终止,重试,忽略", MessageBoxButtons.AbortRetryIgnore);
        switch (result)
        {
            case DialogResult.Abort:
                MessageBox.Show("终止", "about");
                break;
            case DialogResult.Ignore:
                MessageBox.Show("忽略", "Ignore");
                break;
            case DialogResult.Retry:
                MessageBox.Show("重试", "retry");
                break;
        }
    }
      

  2.   

    第4行
    if (str.ToString() == "Abort") ; <-  多个分号 
      

  3.   


    其实 可读性上来说 他这个场景上用if并不影响阅读.所以没必要非用switch
    并且switch效率比if差.所以更没必要非用switch
    3楼正解.