C#第七回:DialogResult

一直没太搞明白这个逻辑是什么意思,今天无意中看到个例子,终于小小的理解了一下。

下面这段代码很好理解,

//create a new dialog, and get the value by using dialogResult
            DialogResult dialogResult=
            MessageBox.Show("是否要创建目录" + textBox1.Text.ToString(), "Tips", MessageBoxButtons.YesNo);
            if (dialogResult==DialogResult.Yes)
            {
                //do sth
            }

以前不理解,是因为经常看到的都是下面这样的

if(MessageBox.Show("删除目录"+textBox1.Text,"Tips",MessageBoxButtons.YesNo)==DialogResult.Yes)
            {
                //do sth
            }
其实两段代码完全等价。。。

猜你喜欢

转载自blog.csdn.net/niaxiapia/article/details/80766849