Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
分配给变量的值错误。。沙马林C#_C#_Xamarin_Visual Studio 2015 - Fatal编程技术网

分配给变量的值错误。。沙马林C#

分配给变量的值错误。。沙马林C#,c#,xamarin,visual-studio-2015,C#,Xamarin,Visual Studio 2015,我目前正在visual studio 2015(C#)上使用xamarin进行一个项目。 在调试过程中,我注意到一些奇怪的行为。与按钮绑定的变量指定了一个错误的值,该值超出了单击按钮时的值 int choose; int chooseBuff = 0; private int clickCounter = 0; private int clickBuffer = 0; private int timerInterval = 1000; Timer time

我目前正在visual studio 2015(C#)上使用xamarin进行一个项目。 在调试过程中,我注意到一些奇怪的行为。与按钮绑定的变量指定了一个错误的值,该值超出了单击按钮时的值

int choose;
    int chooseBuff = 0;
    private int clickCounter = 0;
    private int clickBuffer = 0;
    private int timerInterval = 1000;
    Timer timer;
    Button btnRed, btnBlue, btnYellow;
    Vibrator vibrate;
    List<int> patternList = new List<int>();
    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        // Set our view from the "main" layout resource
        SetContentView(Resource.Layout.Main);
        vibrate = (Vibrator)GetSystemService(Context.VibratorService);
        btnRed = FindViewById<Button>(Resource.Id.btnRed);
        btnBlue = FindViewById<Button>(Resource.Id.btnBlue);
        btnYellow = FindViewById<Button>(Resource.Id.btnYellow);

        //AlertDialog.Builder alert = new AlertDialog.Builder(this);
        //alert.SetTitle("");
        //alert.SetMessage("You Lose!!");
        timer = new Timer();
        timer.Interval = timerInterval;
        timer.Elapsed += Timer_Elapsed;
        timer.Start();

        btnRed.Click += BtnRed_Click;
        btnBlue.Click += BtnBlue_Click;
        btnYellow.Click += BtnYellow_Click;

    }

    private void BtnYellow_Click(object sender, EventArgs e)
    {
        vibrate.Vibrate(100);
        clickBuffer = 3;
        checkClick();
        intervalIncrease();
    }
    private void BtnBlue_Click(object sender, EventArgs e)
    {
        vibrate.Vibrate(100);
        clickBuffer = 2;
        checkClick();
        intervalIncrease();
    }
    private void BtnRed_Click(object sender, EventArgs e)
    {
        vibrate.Vibrate(100);
        clickBuffer = 1;
        checkClick();
        intervalIncrease();
    }
int选择;
int chooseBuff=0;
私有int clickCounter=0;
私有int clickBuffer=0;
专用int TIMERRINTERVAL=1000;
定时器;
按钮btnRed、BTN蓝色、BTN黄色;
振动器振动;
列表模式列表=新列表();
创建时受保护的覆盖无效(捆绑包)
{
base.OnCreate(bundle);
//从“主”布局资源设置视图
SetContentView(Resource.Layout.Main);
振动=(可控震源)GetSystemService(Context.可控震源服务);
btnRed=findviewbyd(Resource.Id.btnRed);
btnBlue=findviewbyd(Resource.Id.btnBlue);
btnYellow=findviewbyd(Resource.Id.btnYellow);
//AlertDialog.Builder alert=新建AlertDialog.Builder(此);
//警报。设置标题(“”);
//SetMessage(“您丢失了!!”);
定时器=新定时器();
timer.Interval=timerInterval;
timer.appeated+=timer\u appeated;
timer.Start();
btnRed.Click+=btnRed\u Click;
点击+=btnBlue\u点击;
单击+=btnYellow\u单击;
}
私有void btneyllow\u单击(对象发送者,事件参数e)
{
振动。振动(100);
点击buffer=3;
选中click();
间隔增加();
}
私有无效BtnBlue_单击(对象发送者,事件参数e)
{
振动。振动(100);
点击buffer=2;
选中click();
间隔增加();
}
私有void BtnRed\u单击(对象发送者,事件参数e)
{
振动。振动(100);
点击buffer=1;
选中click();
间隔增加();
}
单击btnRed时,clickBuffer变量被赋值为3而不是1。其他按钮也是如此。bntBlue将值2分配给clickBuffer,bntYellow将值1分配给clickBuffer。我不知道这个值是从哪里来的。即使我分配了3以外的其他值,比如clickBuffer=5,甚至是“string”,它仍然为btnRed分配了值3。我真的很困惑。。有人能指出我的代码有什么问题吗


这里是整个项目,如果它有帮助的话。我2个月前才开始学习编程,所以请确保您已经准备好查看我的丑陋代码。那里真的很乱。只需编写代码即可完成任务。很确定它有更好的解决方案。。干杯:)…

我测试了它,它工作得很好,我在点击按钮处理程序中设置了值
clickBuffer
。真的吗??它已经困扰我两天了。。我的vs可能是问题吗??但我已经重新启动了几次…请尝试从设备中清除缓存和卸载应用程序,清除解决方案并再次调试。我一回来就会尝试。。但我很确定每次我想运行代码时我都会清理解决方案。。还有其他的可能性吗?确保你没有把你的按钮倒过来命名。我不能告诉你有多少次像这样的错误发生在我身上,仅仅是因为我不小心给我的控件贴错了标签。您认为是btnRed的可能会被标记为btnYellow。