我需要保存一个包含静态国家/地区列表的类以进行缓存。
数据是用
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)
我想把它保存在字典中:
Dictionary<string , Dictionary<int,string>> list = new Dictionary<string, Dictionary<int,string>>();
这是我在课堂上需要的 API:
Countries.getByShortName();// I dont know what to return, I'd love some advise
Countries.getById();// I might need that
Countries.getAll();// I dont know what to return, I'd love some advise
您认为处理这门课的最佳方式是什么?
thanks
怎么样使用一个struct http://msdn.microsoft.com/en-us/library/ah19swz4%28v=VS.100%29.aspx or class http://msdn.microsoft.com/en-us/library/0b0thckt.aspx?
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)
}
然后,您可以将您的国家/地区存储在通用中List http://msdn.microsoft.com/en-us/library/6sh2ey19.aspx, 例如:
List<Country> countries = new List<Country>();
countries.Add(new Country()
{
shortName = "UK",
ID = 1,
longName = "United Kingdom",
});
然后实现给定的方法就变得非常简单:
Country getByShortName(string shortName)
{
foreach (Country country in countries)
{
if (country.shortName == shortName)
{
return country;
}
}
return null;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)