You can pass anything that is a valid constructor parameter. For example, List permits construction from any enumerable, so you can do this:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string[] ab = new string[] { "a", "b" }; | |
List<string> abcd = new List<string>(ab) { "c", "d" }; | |
// abcd has four elements: "a" "b" "c" and "d" | |
// Resulting list is { 1, 2, 3, 4, 5 } | |
var list2 = new List<int>(list) { 4, 5 }; | |
// Resulting list is { 4, 2, 3 } | |
var list3 = new List<int>(list) { [0] = 4 }; | |
string[] ab = new string[] { "a", "b" }; | |
List<string> abcd = new List<string>(ab) { "c", "d" }; | |
// abcd has four elements: "a" "b" "c" and "d" |
this combination notation is useful if you want to clone an existing collection and then make some tweaks to it.