简体   繁体   中英

How save a list<string > in visual studio c# properties setting

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?

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()) )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM