I need a compact way to create a var object and initialize with constant strings
When I use the following
var types = new List<string> {"blah1, blah2, blah3" };
I get only one element in my list. How can I initialize the list with 3 elements.
I need a compact way to create a var object and initialize with constant strings
When I use the following
var types = new List<string> {"blah1, blah2, blah3" };
I get only one element in my list. How can I initialize the list with 3 elements.
If you want to separate the elements by , char, try using the Split method, for sample:
var list = "blah1, blah2, blah3".Split(',') //break by ,
.Select(x => x.Trim()) // remove spaces
.ToList(); // convert to list
Change
var types = new List<string> {"blah1, blah2, blah3" };
to
var types = new List<string> {"blah1", "blah2", "blah3" };