Store Dictionary in application settings

后端 未结 9 1627
感动是毒
感动是毒 2020-11-30 08:28

I have a dictionary of strings that i want the user to be able to add/remove info from then store it for them so it they can access it the next time the program restarts

9条回答
  •  旧时难觅i
    2020-11-30 09:13

    You can also use a System.Collections.Specialized.StringCollection by putting key on even index and values on odd index.

    /// 
    /// Emulate a Dictionary (Serialization pb)
    /// 
    private static string getValue(System.Collections.Specialized.StringCollection list, string key)
    {
        for (int i = 0; i * 2 < list.Count; i++)
        {
            if (list[i] == key)
            {
                return list[i + 1];
            }
        }
        return null;
    }
    
    /// 
    /// Emulate a Dictionary (Serialization pb)
    ///       
    private static void setValue(System.Collections.Specialized.StringCollection list, string key, string value)
    {
        for (int i = 0; i * 2 < list.Count; i++)
        {
            if (list[i] == key)
            {
                list[i + 1] = value;
                return;
            }
        }
        list.Add(key);
        list.Add(value);
    }
    

提交回复
热议问题