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

后端 未结 6 1532
眼角桃花
眼角桃花 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:13

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

    You can't. You can move the declaration to outside the method. Then it becomes a field of the containing class.

    But as many others have said, in this case it's better to return the filename.

    The only things a method "exhibits" to the outside world, are the parameters (it might mutate the objects they reference; or assign to them if they're ref or out) and the return value.

提交回复
热议问题