ListstationList = new List (){"北京","上海","广州","深圳"};
int startIndex = 0;
int endIndex = 0;
private void textbox1_TextChanged(object sender,EventArgs e)
{
startIndex = stationList.IndexOf(textbox1.Text);
Calc();
}
private void textbox2_TextChanged(object sender,EventArgs e)
{
endIndex = stationList.IndexOf(textbox2.Text);
Calc();
}
private void Calc()
{
int diff = endIndex - startIndex;
textbox3.Text = diff <= 0 ? 0 : diff*2;
}
内部维护一个list,计算两个站的index的差
在第二个文本框的textboxchanged里写