I am writing my testcode and I do not want wo write:
List nameslist = new List();
nameslist.Add(\"one\");
nameslist.Add(\"two\");
nam
List<string> nameslist = new List<string> {"one", "two", "three"} ?
Change the code to
List<string> nameslist = new List<string> {"one", "two", "three"};
or
List<string> nameslist = new List<string>(new[] {"one", "two", "three"});
Just lose the parenthesis:
var nameslist = new List<string> { "one", "two", "three" };
Remove the parentheses:
List<string> nameslist = new List<string> {"one", "two", "three"};
var list = new List<string> { "One", "Two", "Three" };
Essentially the syntax is:
new List<Type> { Instance1, Instance2, Instance3 };
Which is translated by the compiler as
List<string> list = new List<string>();
list.Add("One");
list.Add("Two");
list.Add("Three");
It depends which version of C# you're using, from version 3.0 onwards you can use...
List<string> nameslist = new List<string> { "one", "two", "three" };