Hi folks,
The following code will compile OK:
But I'm wondering if it's possible to declare and initialise a List all in one line of code something like this:Code://Method 1 String[] myStrings = {"String_1", "String_2", "String_3"}; List<String> myList = new List<String>(myStrings);
I've looked through the documentation for working with list based collections but I didn't see any constructors or methods for doing it via method 2. I'm assuming then that it's not possible to do it that way, but If that's the case could someone give me a reason why that's not allowed?Code://Method 2 List<String> myList = new List<String>("String_1", "String_2", "String_3");
Thanks again for your help.




Reply With Quote