What parameter should I specify for Properties.Settings.Default.History so that it doesn't give an error with Null?

32 views Asked by At

I create the "History" parameter through the project properties and I'm trying to put a value in that parameter and save it:

 Properties.Settings.Default.History.Add("00:30");
 Properties.Settings.Default.Save();

But it's giving me an error: System.NullReferenceException: "Object reference not set to an instance of an object." Fifteen.Properties.Settings.History.get вернул null.

what value do I need to enter in the parameter to make the error disappear?

Additional information: I have a listbox called elapsedtimeitem, it should store all the results of a user's playthroughs. I also need to make sure that when I restart the application, these results (listbox) are not erased. That is, all Listbox items will remain. For this I want to use Properties.Settings.Default.History. I made the type for this property system collection specialized string collection. I want that when I get a new user result (string) it will be written to Properties.Settings.Default.History. And from Properties.Settings.Default.History to write the value to elapsedtimeitem. I made the following code:

Properties.Settings.Default.History.Add(elapsedtimeitem);
Properties.Settings.Default.Save();

But I got an error. To be sure that it's not the variable I changed the code for the test to:

Properties.Settings.Default.History.Add("00:30");
Properties.Settings.Default.Save();

And it gives an error with null. But what value should I enter? It doesn't accept any string as a parameter, it doesn't accept an array either. I'm obviously doing something wrong, but I don't understand what.

0

There are 0 answers