我如何只打开带有 .txt 扩展名的文件,如果文件不是 .txt 文件,我希望我的程序弹出一条错误消息我想要一个可以在下面修改此代码的代码
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog of = new OpenFileDialog();
of.ShowDialog();
textBox1.Text = of.FileName;
}
有人可以帮忙假设我想放这个循环
if fileextension is .txt then
OpenFileDialog of = new OpenFileDialog();
of.ShowDialog();
textBox1.Text = of.FileName;
else show error message(like can not open this file)