i've got dictionary<string, double>
save , restore when restart application. have heard cannot store dictionary in c#, trying make workaround.
currently have made string variable in setting called db
, , trying use this:
var settings = dict.toarray(); var prop = properties.settings.default.db;
and make prop = settings;
thus far have done this, although working..
private void savesettings() { var settings = spampercentage.toarray(); var prop = properties.settings.default.db; string res = string.join(",", settings); prop = res; } private void loadsettings() { var prop = properties.settings.default.db; var dictionary = prop.todictionary(item => item.key, item => item.value); }
edit values in dictionary looks this:
{[john, 0,53]} {[ivone, 0,44]} etc.
@edit using julien json idea, have made:
string prop = properties.settings.default.db; private void savesettings() { prop = jsonconvert.serializeobject(dict); properties.settings.default.save(); } private void loadsettings() { dict= jsonconvert.deserializeobject<dictionary<string, double>>(prop); }
when hit program, , use savesettings method, can see has values. reboot program, , try loadsettings , null.
i had similar problem while ago. ended using json serialization serialize dictionary string, store in application settings, , deserialize dictionary when needed it.
string strdictionaryasstring = jsonconvert.serializeobject(dtndictionary); var dtndictionary = jsonconvert.deserializeobject<dictionary<string, double>>(strdictionaryasstring );
Comments
Post a Comment