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 planing to do a program that if i select A city i get first row if B city i get 2 row

asked May 15, 2013 at 10:10
1
  • Please concretize your question... Commented May 15, 2013 at 10:27

3 Answers 3

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
Sign up to request clarification or add additional context in comments.

1 Comment

Was just about to write the same :)
0

I would rather do it as

if (LstDestinationCity.Text == City[i,i])
{
 // ...
}
Carsten
11.7k7 gold badges43 silver badges66 bronze badges
answered May 15, 2013 at 10:23

1 Comment

this would crash the application as it is. When he try to access City[1,1]
0

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

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.