私はこれが正しく機能するようになるのに本当に近づいていますが、何かが足りないだけです。それはおそらく非常に単純です。私は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);
}
}
}