Hashtable for my Distance Finder Program
Hey all i need help with the following code. Ive set up a Hashtable but it seems to have errors, i've never done one of these before. Here is some of my code as an example:
private Hashtable _distances;
_distances=new Hashtable();
Hashtable birminghamDistances=new Hashtable();
birminghamDistances.Add("Birmingham",0);
birminghamDistances.Add("Cardiff",103);
...
_distances.Add("Birmingham",birminghamDistances);
Hashtable distanceForSelectedTown = (Hashtable)_distances[txtFromTown.Text];
int distance=(int)distanceForSelectedTown[txtToTown.Text];
txtDistance.Text=distance.ToString();
I'm getting errors on line 1 (private Hastable), line 3 (_distances), line 5 (new Hashtable), line 9 (_distances) and line 11 (distances[txtFromTown.Text]
What im trying to make is this:
http://www.wrestlefury.com/distancefinder.jpg
When two places are entered in the textboxes and the calculate distance button is pressed, i want the distance to show up in the Distance Textbox. But i cant do this Hashtable, could someone please help?
Regards,
Rob
Re: Hashtable for my Distance Finder Program
What are the errors? Are you including the System.Collections namspace?
Re: Hashtable for my Distance Finder Program
no whats that? Ive put in brackets what the errors are. Im putting this hashtable is under btnDistance.
Re: Hashtable for my Distance Finder Program
If your getting an error like
"the type or namespace name 'Hashtable' could not be found
add
using System.Collection;
to the start of your project.
Re: Hashtable for my Distance Finder Program
Ive done that it still has errors, there must be something wrong with my code.