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

前端 未结 5 1822
故里飘歌
故里飘歌 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:47

    why wont you make your own class?

    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)
    }
    

    then just make another class, that will contain methods you need

    class Countries
    {
       List countries = new List();
    
       public void Add(Country c)
       {
          countries.Add(c);
       }
    
       public List getByShortName();
       public List  getById();
       public List  getAll();
    }
    

提交回复
热议问题