-1
int numberint = 0;

List<string> Listshow= new List<string>();

//and this Listshow item =

Listshow.Add("number" + numberint.ToString()); //(my Listshow item == number1,number2,number3,number4 and...number60)

How to save this Listshow in (Properties.Settings.Default) and re-open the form of this Listshow with its items?

Please can you provide save and load code?

  • LIst Listshow = newList(); – professional Jul 14 '21 at 03:57
  • Duplicate and/or **[Suggested Reading](https://stackoverflow.com/questions/2890271/how-to-save-a-liststring-on-settings-default)** – Ňɏssa Pøngjǣrdenlarp Jul 14 '21 at 04:09
  • shouldn't rely on the ide. just read/write files. – Lei Yang Jul 14 '21 at 04:13
  • @LeiYang a particularly useless piece of advice, imho. We rely on the IDE to read and write files all the time. If you're advocating not making use of various mechanisms to make like easier then you should perhaps stop using any provided libraries, and write your own operating system, graphics drivers, command prompt, io routines etc and then finally you'll have enough supporting infrastructure to write Hello World – Caius Jard Jul 14 '21 at 05:26
  • personally i find it difficult to use. in what circumstance would you store 60 numbers in ide, and then possibly edit the `*.exe.config`/or even some deeply hidden files under application data folder before app runs? – Lei Yang Jul 14 '21 at 05:42
  • Not sure what you're talking about, @LeiYang - app settings makes life easy. You want to store a string or bool or int etc, you open the settings designer, add a setting name, type and value, then it becomes available in the code as a typed variable. You can even bind any property of a visual control to it so that control just remembers its setting across app shutdown/restart with nearly zero code. You're saying "read and write and parse the files yourself" when vs will write all that code for you, which is like advocating writing your own json parser.No one would, they just use Newtonsoft/STJ – Caius Jard Jul 14 '21 at 05:56
  • if not for edit(setting), then why not just hardcode? but the VS settings is not easy to edit. – Lei Yang Jul 14 '21 at 05:58
  • If it's hard you're doing it wrong. VS settings is easier than writing hello world in notepad. "Why not just hardcode" - good job Microsoft doesn't take that approach with IIS huh? – Caius Jard Jul 14 '21 at 06:01

1 Answers1

0

The settings system provides a value type called StringCollection; make a setting of that type and scope user

Upon form load, add the contents of the collection to your list, perhaps with yourList.AddRange(Properties.Settings.Default.YourStringCollectionSetting)

Upon form closing (or whenever you save your settings) clear the settings string collection (Properties.Settings.Default.YourStringCollectionSetting.Clear())

and addrange your current list to it (Properties.Settings.Default.YourStringCollectionSetting.AddRange(yourList.ToArray()))

Caius Jard
  • 72,509
  • 5
  • 49
  • 80