Collection Initialisers and Spread
Initialise collections inline. C# 12 collection expressions use [ ] and .. to spread.
Example
int[] a = [1, 2, 3];
List<int> l = [..a, 4, 5];
var d = new Dictionary<string, int> { { "x", 1 } };
Console.WriteLine(string.Join(",", l));Exercise
Spread items.
[a, 4]
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.