0
        int i;
        int [,] Prices = new int [2, 7]{{1,2,3,4,5,6,7},{700,600,500,400,300,200,100}};
        string[,] City = new string [2,1]{{"A"},{"B"}}; 
        bool found = false;
        for (i = 0; i <= City.Length -1; i++)
          // for (y = 0; y <= City.Length - 1; y++)


        {
            if (LstDestinationCity.Text == City[i]) <<-- i get error here
          {

我打算做一个程序,如果我选择 A 城市我得到第一行如果 B 城市我得到 2 行

4

3 回答 3

3

我认为那是因为 City[i] “不包含任何东西”你应该检查 City[i,0]

if (LstDestinationCity.Text == City[i,0])// this should access the first element which is the text you are looking for
于 2013-05-15T10:13:21.580 回答
0

我宁愿这样做

if (LstDestinationCity.Text == City[i,i])
{
    // ...
}
于 2013-05-15T10:23:01.983 回答
0

您的City变量不需要是二维数组。如果将其更改为一维数组,则可以使用一个索引而不是 2 来访问这些值。

string[] City = new string [2]{"A","B"};
于 2013-05-15T10:49:40.770 回答