How do I use a variable declared in a method, outside that method?

后端 未结 6 1495
眼角桃花
眼角桃花 2021-01-27 00:26

I am using VS 2008 (C#)... I have created a function in a GlobalClass to use it globally.. This is for opening a dialog box. When I call this function in my method it works but

6条回答
  •  半阙折子戏
    2021-01-27 01:04

    Do it like this -

    static class GlobalClass
    {
        public static string OFDbutton()
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "Image files|*.jpg;*.jpeg;*.png;*.gif";
            DialogResult dr = ofd.ShowDialog();
            return ofd.FileName;
        }
    }
    
    lable1.text = GlobalClass.OFDbutton();
    

提交回复
热议问题