Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert StringCollection to List<String>

Normally, I'd choose List<String> [or, in VB, List(Of String)] over StringCollection whenever possible: see also Best string container.

However, as it seems, generics — and hence, List<String> — are apparently not supported in VS 2008's settings designer. Therefore, if I want to use a list of strings in my user settings, I have to resort to using a StringCollection there.

Now as I don't want to see StringCollection throughout my code, I need to convert it to List<String>. How do I do this efficiently? Or, even better, am I mistaken and there is a way to use List<String> in settings designer?

EDIT: I have to use .NET 2.0.

like image 680
CarstenK Avatar asked May 10 '09 00:05

CarstenK


2 Answers

Converting StringCollection to List<string> is wonderfully simple if you're using .NET 3.5.

var list = stringCollection.Cast<string>().ToList(); 

Regarding your second question, I do seem to recollect that it is possible to use List<string> in the settings designer of Visual Studio. If you select custom type then browser to the appropiate type, it should work. However, I could be mistaken on that, so I'll need to verify it.

like image 175
Noldorin Avatar answered Sep 21 '22 10:09

Noldorin


stringCollection.Cast<string>().ToList()

like image 34
Tasawer Khan Avatar answered Sep 19 '22 10:09

Tasawer Khan