2013-05-15 64 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"};