C# Storing string,int,string in an accessable variable

前端 未结 5 1825
故里飘歌
故里飘歌 2021-01-26 05:16

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         


        
5条回答
  •  逝去的感伤
    2021-01-26 05:57

    I think you need to create your own class incapsulating all three fields and to use own Collection of It. For example:

    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 
    {
     //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
    }
    

    If you like quick search then to use a pair of dictionaries:

        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  Ids = new Dictionary  ();
          Dictionary  shortNames = new Dictionary  ();
    
         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
        }
    

提交回复
热议问题