我真的很接近让它正常工作,但我只是错过了一些东西。这可能很简单。我对 C# 很陌生。我有一个名为的文本框txtState
,您可以在其中输入一个城市(我知道),以查看您是否访问过这个城市。txtAnswer
当您单击btnVisited
按钮时,它会向另一个文本框输出响应。现在它只是将我输入的任何内容输入到txtState
框中并说它是数组中的 0 位置。我忘了提到我需要在数组中包含这个城市的位置,并将其输出到文本框。这是我的代码:
namespace Test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
txtAnswer.Text = "";
txtState.Text = "";
}
private void button3_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnVisited_Click(object sender, EventArgs e)
{
string[] CityName = {"Columbus", "Bloomington", "Indianapolis",
"Fort Wayne", "Greensburg", "Gary", "Chicago", "Atlanta", "Las Vegas"};
bool visitedbool;
int subscript;
subscript = 0;
visitedbool = false;
string QueryCity;
QueryCity = txtState.Text.ToUpper();
do
{
subscript += 0;
if (subscript == 0)
txtAnswer.Text = "You have visited" + " " + QueryCity + " " + "It is the" + " " + subscript + " " + "city you have visited.";
else if (subscript == 1)
txtAnswer.Text = "You have visited" + " " + QueryCity + " " + "It is the" + " " + subscript + " " + "st city you have visited.";
else if (subscript == 2)
txtAnswer.Text = "You have visited" + " " + QueryCity + " " + "It is the" + " " + subscript + " " + "nd city you have visited.";
else if (subscript == 3)
txtAnswer.Text = "You have visited" + " " + QueryCity + " " + "It is the" + " " + subscript + " " + "rd city you have visited.";
else if (subscript == 4 - 8)
txtAnswer.Text = "You have visited" + " " + QueryCity + " " + "It is the" + " " + subscript + " " + "th city you have visited.";
else
txtAnswer.Text = "You have not visited this city.";
}
while (visitedbool == true);
}
}
}