I have a class that contains a List<>
of objects. For this example I will say the objects are a basic class as below:
public class City
{
private string name;
private string country;
public string Name
{
get
{
return name;
}
set
{
name = value;
}
}
}
Normally I would refer to these objects like so:
List<City> theList = new List<City>();
City theCity = theList[0];
What I would like to do is refer to the list as follows:
List<City> theList = new List<City>();
City theCity = theList["London"];
Where London is the name property of one of the cities.
How do I achieve this? At present I have been constructing "find" type methods that return me the city in question. What I need is to be able to refer by Key.