Skip to content

Instantly share code, notes, and snippets.

@poojarsn
Created November 29, 2018 05:02
Constructor with collection Initializer
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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment