我需要调用一个数组来获得下面的程序工作,但我无法弄清楚。我不知道什么是或不工作,因为我无法获得列表框填充。以下是代码。无法获取列表框项目来填充C#
using System.IO;
namespace Test_Your_Knowledge__Game
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string questionOne;
string questionTwo;
string questionThree;
string firstQuestion = ("Who is a Silk Worm?");
string secondQuestion = ("What does Sapience mean?");
string thirdQuestion = ("What is Tainou?");
string firstAnswer = ("Onycho");
string secondAnswer = ("Wisdom");
string thirdAnswer = ("A Wolf");
int count = 0;
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void playButton_Click(object sender, EventArgs e)
{
string name;
string email;
name = nameTextBox.Text;
email = emailTextBox.Text;
StreamWriter outputFile;
outputFile = File.CreateText("Submission_List.txt");
outputFile.WriteLine(name);
outputFile.WriteLine(email);
outputFile.WriteLine(count);
outputFile.Close();
}
private void myArray(string[] strArray, string value)
{
bool found = false;
int index = 0;
int position = -1;
while (!found && index < strArray.Length)
if (strArray[index] == value)
{
found = true;
position = index;
index++;
}
string[] questionOneArray = { "1) Beebo", "2) Bael", "3) Onycho", "4) Ilion" };
string[] questionTwoArray = { "1) Beauty", "2) Cursed", "3) Properity", "4) Wisdom" };
string[] questionThreeArray = { "1) Imp", "2) Wolf", "3) Trow", "4) Elf" };
foreach (string length in strArray)
{
try
{
if (questionOneArray[index] != firstAnswer)
{
questionOne = (firstQuestion + "" + questionOneArray);
listBox1.Items.Add(questionOne.ToString());
found = false;
}
else
{
found = true;
count++;
}
{
if (questionTwoArray[index] != secondAnswer)
{
questionTwo = (secondQuestion + "" + questionTwoArray);
listBox1.Items.Add(questionTwo.ToString());
found = false;
}
else
{
found = true;
count++;
}
{
if (questionThreeArray[index] != thirdAnswer)
{
questionThree = (thirdQuestion + "" + questionThreeArray);
listBox1.Items.Add(questionThree.ToString());
found = false;
}
else
{
found = true;
count++;
}
}
}
}
catch (Exception)
{ }
}
}
}
这是很难理解你正在尝试做的。将需要更多的信息,如你想要什么输出,你得到什么,你卡在哪里? – Codeek 2014-12-06 11:04:30
对不起....我试图在列表框中写下问题和数组,以便玩家可以选择答案。如果它是正确的,它会在回答三个问题并写入文件结束时计算得分。该程序运行,但我不能得到任何东西写入列表框。 – ssm 2014-12-06 14:09:32
您意识到第**步**是将问题和答案放入数组中。对? – ja72 2014-12-06 16:35:14