- C# Storing string,int,string in an accessable variable
- 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>>();
- 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
- public class Country
- {
- public string ShortName {get;set;}
- public int ID {get;set;}
- public string LongName { get; set; }
- }
- public class Countries
- {
- static Dictionary<string, Country> dict = new Dictionary<string, Country>();
- public static void Add(Country country)
- {
- if (!dict.ContainsKey(country.ShortName))
- dict.Add(country.ShortName, country);
- }
- public static Country GetByShortName(string ShortName)
- {
- if (dict.ContainsKey(ShortName))
- return dict[ShortName];
- return null;
- }
- public static Country GetById(int id)
- {
- var result = from country in dict
- where country.Value.ID==id
- select new Country
- {
- ID = country.Value.ID,
- ShortName = country.Value.ShortName,
- LongName = country.Value.LongName
- };
- return result.SingleOrDefault();
- }
- public static List<Country> GetAll()
- {
- var result = from country in dict
- select new Country
- {
- ID = country.Value.ID,
- ShortName = country.Value.ShortName,
- LongName = country.Value.LongName
- };
- return result.ToList();
- }
- }
- 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<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;
- }
- public class Country
- {
- public string ShortName {get; set;}
- public int ID {get; set;}
- public string LongName {get; set;}
- }
- var UK = _countries["UK"];
- UK.ID...
- UK.LongName...
- class Country
- {
- public string shortName { get; set; } //Primary Key - (IL or UK for example)
- public int ID { get; set; } //Unique - has no meaning, but needs to be saved
- public string longName { get; set; } //(Israel or United Kingdom for example)
- }
- class Countries
- {
- List<Country> countries = new List<Country>();
- public void Add(Country c)
- {
- countries.Add(c);
- }
- public List<Country> getByShortName();
- public List<Country> getById();
- public List<Country> getAll();
- }
- class CountryInfo
- {
- 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)
- }
- class CountryCollection : Collection <CountryInfo>
- {
- //Implement methods what you need
- void getByShortName();// I dont know what to return, I'd love
- void getById();// I might need that
- void getAll();// I dont know what to return, I'd l
- }
- class CountryInfo
- {
- 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)
- }
- class CountryCollection
- {
- Dictionary <int, string> Ids = new Dictionary <int, string> ();
- Dictionary <string, string> shortNames = new Dictionary <string, string> ();
- void Add (CountryInfo info)
- {
- Ids.Add (info.ID, info.longName);
- shortnames.Add(info.ID, info.longName);
- }
- //Implement methods what you need
- void getByShortName();// I dont know what to return, I'd love
- void getById();// I might need that
- void getAll();// I dont know what to return, I'd l
- }