2013-05-15 63 views
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 
      { 

IM刨做一個程序,如果我選擇一個城市,我得到第一排在B市,我得到2排C#數組,字符串,錯誤

+0

問題是什麼? –

+0

請具體化您的問題... – kapsi

回答

3

我認爲這是因爲市[I]「唐」牛逼包含任何」你應該檢查市[I,0]

if (LstDestinationCity.Text == City[i,0])// this should access the first element which is the text you are looking for 
+0

剛剛寫的相同:) –

+0

您最好感謝:P – user2385345

+0

沒問題隊友 –

0

我寧願做它作爲

if (LstDestinationCity.Text == City[i,i]) 
{ 
    // ... 
} 
+0

這會使應用程序崩潰。當他嘗試訪問城市[1,1]時, –

0

City變量並不需要是一個二維數組。如果將其更改爲一維數組,則可以使用一個索引而不是2來訪問這些值。

string[] City = new string [2]{"A","B"};