My question is very simple. How can you store an double array in the settings of the program, and getting it out of it.
I already got this:
string[,] user_credits = new string[user_credits_array, 10];
user_credits[new_user_id, 0] = user_name;
user_credits[new_user_id, 1] = user_email;
user_credits[new_user_id, 2] = user_acc_name;
user_credits[new_user_id, 3] = user_acc_pass;
user_credits[new_user_id, 4] = sSelectedClient;
user_credits[new_user_id, 5] = server_inkomend;
user_credits[new_user_id, 6] = server_uitgaand;
user_credits[new_user_id, 7] = server_port + "";
user_credits[new_user_id, 8] = ssl_state;
So as you can see, am i using the id of the user to store the info together. And I'm storing it this way:
Properties.Settings.Default.user_credits = user_credits;
Properties.Settings.Default.Save();
Am I doing it right? is now the array still in the user settings?
And how can I get it out of it (the settings with the right user id)?
I know it might sound crazy, but i think this is the best way. But if you guys know an better way, tell me. I
Edit 1:
I've got this piece of code:
string[,] user_credits = new string[user_credits_array, 10];
user_credits[new_user_id, 0] = user_name;
user_credits[new_user_id, 1] = user_email;
user_credits[new_user_id, 2] = user_acc_name;
user_credits[new_user_id, 3] = user_acc_pass;
user_credits[new_user_id, 4] = sSelectedClient;
user_credits[new_user_id, 5] = server_inkomend;
user_credits[new_user_id, 6] = server_uitgaand;
user_credits[new_user_id, 7] = server_port + "";
user_credits[new_user_id, 8] = ssl_state;
MySettings settingsTest = new MySettings();
settingsTest.Save(MySettings.GetDefaultPath());
MySettings anotherTest = MySettings.Load(MySettings.GetDefaultPath());
And after running the code, this is how the XML file looks like:
<Complex name="Root" type="WeProgram_Mail.MySettings, WeProgram_Mail, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<Properties>
<Null name="user_credits" />
</Properties>
Now I don't understand why the array isn't saved. Because I've got this line
public string[,] user_credits { get; set; }
And I thought that would pick up the usersettings from the array, but somehow they don't.
Use
System.Collections.Specialized.StringCollection
for setting and add a XML String (contain your additional properties like 'user_name' or 'user_email') to each string:and parse XML when you need properties.
Ah, I see the problem. As you see in the XML file, the array in the MySettings instance(settingsTest) is null. That is because you fill the array outside the settingsTest object and never touch or initialize settingsTest.user_credits...
Try the following:
Well, usually I just use http://www.sharpserializer.com/en/index.html
It is childishly easy to use, fast, and can serialize more or less anything, including Dictionary, etc. Nice thing is, that you can serialize to multiple target formats like binary.
EDIT: Example for Serialization with SharpSerializer. Have not compiled the code, but should be fine. Drawback: A property to be stored has to be public...