比较两个数组并给出结果。 [英] Comparing two arrays and giving results.

查看:92
本文介绍了比较两个数组并给出结果。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在编写一个程序,用户可以从带有无线电按钮的组合框中进行选择,并根据选择将无线电按钮的文本放入标签中。我创建了两个数组,一个用于用户选择,文本用标签,另一个数组用正确的答案。我想比较两个数组并计算正确答案的数量和错误答案的数量,并将数字放在两个标签中。这是我的数组代码:

Hello, i'm writing a program where the user makes choices from a groupbox with radiobuttons and the text of the radiobutton are put in lables depending on the choice. I have made two arrays, one for user choices with the text in lables and another array with the correct answers. I want to compare both arrays and count the number of correct answers and the number of wrong answers and put the numbers in two lables. Here's my code for the arrays:

const int SIZE = 5;
string [] userAnswers = new string[SIZE];
string[] decompTimeArray = new string[SIZE];
int userChoice = 0;

private void exitBtn2_Click(object sender, EventArgs e)
{
    this.Close();
}

public void usersAnswers()
{
    const int SIZE = 5;
    string[] userAnswers = new string[SIZE];

    userAnswers[0] = newspaperLbl.Text;
    userAnswers[1] = aluminumCanLbl.Text;
    userAnswers[2] = glassBottleLbl.Text;
    userAnswers[3] = plasticbagLbl.Text;
    userAnswers[4] = cupLbl.Text;
}

public void correctAnswers()
{
    const int SIZE = 5;
    string[] decompTimeArray = new string[SIZE];
    decompTimeArray[0] = "6 Weeks";
    decompTimeArray[1] = "10-20 Years";
    decompTimeArray[2] = "80-200 Years";
    decompTimeArray[3] = "1,000,000 Years";
    decompTimeArray[4] = "Never";
}



非常感谢您的帮助!


Your help is greatly appreciated!

推荐答案

1.Like Sergey在您上面说不应该使用字符串,在你的情况下指示创建一个具有两个属性的对象:ID(int)和Text(字符串),然后在UI控件中使用这两个属性(显示给用户的文本文本和ID集)进入UI控件的标签属性。



2.如果你想要一个更高级的解决方案,应该从资源中读取文本值,如果您希望(至少在不久的将来)实现多语言支持,则特别需要这样做。
1.Like Sergey said above you shouldn't use strings, in you case is indicated to create an object that have two properties: ID (int) and Text (string), then to use both in your UI controls (Text for Text shown to the user, and ID set into the Tag property of the UI control).

2.If you want an even advanced solution, the text values should be read from resources, and in this is specially needed if you want, at least in the near future, to implement multilingual support.


C#SequenceEqual:





http://www.dotnetperls.com/sequenceequal [ ^ ]
C# SequenceEqual :


http://www.dotnetperls.com/sequenceequal[^]


这篇关于比较两个数组并给出结果。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆