如何在C#中重置全局变量 [英] how to reset global variable in c#
本文介绍了如何在C#中重置全局变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我制作了一个桌面应用程序,并使用了一个全局变量来计算按钮的点击次数.
但是当我重置全局变量时,它不会重置.
我将全局变量用作
Hi,I made a desktop application and using a global variable for counting the number of clicks on a button.
but when i reset the global variable its not reset.
i used global variable as
int i=0;
我在重置按钮上写这个
and i am writing this at reset button
int i=0;
重设全局变量是否错误?
请帮帮我.
我是编码新手.
提前致谢.
Is i am wrong to reset global variable.
Please help me out.
I am new in coding.
Thanks In Advance.
推荐答案
C#
没有全局变量.您可能是说一个类成员变量吗?
在重置"按钮中,您声明(并初始化)变量的新实例,从而遮盖(可能的)类成员变量.
您必须从以下位置更改(在重置"按钮命令处理程序中):
C#
has no global variables. Possibly do you mean a class member variable?
In the reset button you are declaring (and initializing) a new instance of the variable and thus shadowing the (possible) class member variable.
You have to change (in the reset button command handler) from:
int i = 0;
到
to
i = 0;
仅在重置按钮上写入
write on reset button only
i=0;
这篇关于如何在C#中重置全局变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文