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 planing to do a program that if i select A city i get first row if B city i get 2 row
-
Please concretize your question...kapsiR– kapsiR2013年05月15日 10:27:46 +00:00Commented May 15, 2013 at 10:27
3 Answers 3
I think that's because City[i] "don't contain anything" you should check City[i,0]
if (LstDestinationCity.Text == City[i,0])// this should access the first element which is the text you are looking for
answered May 15, 2013 at 10:13
Fabio Marcolini
2,3952 gold badges25 silver badges32 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
Adam Bilinski
Was just about to write the same :)
I would rather do it as
if (LstDestinationCity.Text == City[i,i])
{
// ...
}
Carsten
11.7k7 gold badges43 silver badges66 bronze badges
1 Comment
Fabio Marcolini
this would crash the application as it is. When he try to access City[1,1]
Your City variable does not need to be a two dimensional array. If you change it to a one dimensional array you can access the values with one index instead of 2.
string[] City = new string [2]{"A","B"};
answered May 15, 2013 at 10:49
juharr
32.4k4 gold badges60 silver badges95 bronze badges
Comments
default