C# 显示没有错误答案的总分

C# 显示没有错误答案的总分,c#,android,xamarin,C#,Android,Xamarin,我制作了一个Android应用程序,但我有一个问题 btnCalc.Click += (object sender, EventArgs e) => { totalScore = Convert.ToInt32(input1.Text) + Convert.ToInt32(input2.Text); total.Text = totalScore.ToString(); }; 比赛进行了13轮。每轮有一个文本框 这是一个小游戏,你可以在游戏中控制比分。 你必须说这一轮你能

我制作了一个Android应用程序,但我有一个问题

btnCalc.Click += (object sender, EventArgs e) => {
    totalScore = Convert.ToInt32(input1.Text) + Convert.ToInt32(input2.Text);
    total.Text = totalScore.ToString();
};
比赛进行了13轮。每轮有一个文本框

这是一个小游戏,你可以在游戏中控制比分。 你必须说这一轮你能得多少分(总是数字) 但当您给出错误答案时,文本框文本将是:
×

最后,我想让大家看看谁赢了。 如何在没有错误答案的情况下添加这些数字

当您长按文本框时,它将是一个
×

btnCalc.Click += (object sender, EventArgs e) => {
int input1 =0;
int input2 =0;
try{
   input1 = Convert.ToInt32(input1.Text);
}
catch{
// do nothing, the input1 will remain 0
}
try{
   input2 = Convert.ToInt32(input2.Text);
}
catch{
// do nothing, the input2 will remain 0
}

    totalScore = input1+ input2;
    total.Text = totalScore.ToString();
};
或:


如果您有一个包含所有文本框的数组,您可以执行以下操作:

        var items = new[]
        {
            new TextBox { Text = "10" },
            new TextBox { Text = "20" },
            new TextBox { Text = "x" },
            new TextBox { Text = "4" },
            new TextBox { Text = "x" },
        };

        var total = (from it in items where it.Text != "x" 
            select Convert.ToInt32(it.Text)).Sum();
尽管当文本框包含的值不是“x”也不是数字时,这不适用于这种情况。以下可能更好:

var items = new[]
        {
            new TextBox { Text = "10" },
            new TextBox { Text = "20" },
            new TextBox { Text = "x" },
            new TextBox { Text = "4" },
            new TextBox { Text = "x" },
        };

        int val = 0;
        var total = (from it in items where Int32.TryParse(it.Text, out val)
                     select val).Sum();

如何将文本框连接到数组文本框?遍历文本框并选择是否以某种方式将它们作为数组的一部分(可能通过命名约定)。或者只使用所有文本框,假设没有文本框包含您不需要使用的数值。或者只是手动创建一个包含您知道需要使用的文本框的数组。我的解决方案旨在展示如何从感兴趣的文本框中获取总数,而不是如何选择要使用的文本框。更正英语错误+删除无用的单词
var items = new[]
        {
            new TextBox { Text = "10" },
            new TextBox { Text = "20" },
            new TextBox { Text = "x" },
            new TextBox { Text = "4" },
            new TextBox { Text = "x" },
        };

        int val = 0;
        var total = (from it in items where Int32.TryParse(it.Text, out val)
                     select val).Sum();