Developer bit

New in C# 12: Collection expressions

Creating collections becomes simpler in C# 12 using collection expressions. We can also make use of the spread operator .. to copy the values from a collection.

New in C# 12: Collection expressions

Creating collections becomes simpler in C# 12 using collection expressions. We can also make use of the spread operator .. to copy the values from a collection.

Log(new[] { "one", "two", "three" });
Log(["one", "two", "three"]);
string[] values = ["one", "two", "three"];
Log([.. values, "four", .. (string[])["five", "six"]]);
void Log(string[] values) {}

More info can be found in the documentation.

Feel free to update this developer bit on GitHub, thanks in advance!

Enjoying the blog?

Support my work

If you enjoyed this post and found it useful, consider supporting my work. It helps me keep creating and sharing content like this. Thank you!