C# 用于检查整数状态的回调函数
我正在为我的编程类制作一个WP7应用程序,我想实现一个用于检查整数状态的回调函数,而不是调用用于显式检查的函数。整数在按下按钮时迭代,当它达到最大输入时,我希望有一个回调函数来检查它,但我不完全确定如何实现它C# 用于检查整数状态的回调函数,c#,windows-phone-7,callback,C#,Windows Phone 7,Callback,我正在为我的编程类制作一个WP7应用程序,我想实现一个用于检查整数状态的回调函数,而不是调用用于显式检查的函数。整数在按下按钮时迭代,当它达到最大输入时,我希望有一个回调函数来检查它,但我不完全确定如何实现它 private void Right_Button_Click(object sender, RoutedEventArgs e) { if (current_input <= MAX_INPUT) { user_inp
private void Right_Button_Click(object sender, RoutedEventArgs e)
{
if (current_input <= MAX_INPUT)
{
user_input[current_input] = 3;
current_input++;
display_result();
}
}
#endregion
void display_result()
{
//will move alot of this to the a result page
DateTime time_end = DateTime.Now;
TimeSpan difference = time_end.Subtract(timer);
time_stamp = difference.ToString();
bool combination_error = true;
if (current_input == 4)
{
for (int i = 0; i < MAX_INPUT; i++)
{
if (user_input[i] != combination[i])
{
combination_error = false;
break;
}
}
if (combination_error)
{
MessageBox.Show("Correct combination The timer is " + time_stamp);
}
else
{
MessageBox.Show("Wrong combination");
}
}
}
private void右键单击(对象发送者,路由目标)
{
如果(current_input您不能真正将回调函数放在整数上,但是,您可以将整数作为属性公开,并从属性设置器调用函数。请看以下示例:
private int _myInteger = 0;
private int MyInteger {
get
{
return _myInteger;
}
set
{
_myInteger = value;
if (_myInteger <= MAX_INPUT)
MyCallBackFunction();
}
}
private void Right_Button_Click(object sender, RoutedEventArgs e)
{
MyInteger = MyInteger + 1;
// Do your other stuff here
}
private void MyCallBackFunction()
{
// This function executes when your integer is <= MAX_VALUE
// Do Whatever here
display_result();
}
private int\u myInteger=0;
私有整型整数{
得到
{
返回_myInteger;
}
设置
{
_myInteger=值;
如果(_myInteger)您尝试了什么?发布一些代码以便我们能够更好地帮助您。