I need the above feature because I can only store StringCollection to Settings, not List of strings.
How does one convert List into StringCollection?
How about:
StringCollection collection = new StringCollection();
collection.AddRange(list.ToArray());
Alternatively, avoiding the intermediate array (but possibly involving more reallocations):
StringCollection collection = new StringCollection();
foreach (string element in list)
{
collection.Add(element);
}
Converting back is easy with LINQ:
List<string> list = collection.Cast<string>().ToList();
Use List.ToArray()
which will convert List to an Array which you can use to add values in your StringCollection
.
StringCollection sc = new StringCollection();
sc.AddRange(mylist.ToArray());
//use sc here.
Read this
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With