I need to save a class with list of countries in statics for caching.
the data is built with
string shortName //Primary Key - (IL or UK for example)
int
How about using a struct or class?
class Country
{
string shortName; // Primary Key - (IL or UK for example)
int ID; // Unique - has no meaning, but needs to be saved
string longName; // (Israel or United Kingdom for example)
}
You can then store your countries in a generic List, for example:
List countries = new List();
countries.Add(new Country()
{
shortName = "UK",
ID = 1,
longName = "United Kingdom",
});
Implementing your given methods then becomes very straightforward:
Country getByShortName(string shortName)
{
foreach (Country country in countries)
{
if (country.shortName == shortName)
{
return country;
}
}
return null;
}