devblog

C# 12: New Features You’ll Love

C# 12 brings some amazing new features that make coding more expressive and efficient.

Collection Expressions

Collection expressions make it easier to work with collections:

var numbers = [1, 2, 3, 4, 5];
var moreNumbers = [.. numbers, 6, 7, 8];

Default Lambdas

Default parameters for lambda expressions:

Func<int, int> add = (x, y = 10) => x + y;
Console.WriteLine(add(5)); // Output: 15

File-Local Types

Type visibility limited to the file:

file class InternalHelper
{
    public static void HelperMethod() { }
}

Conclusion

C# 12 continues to make the language more powerful and expressive. These features will help you write cleaner, more maintainable code.


Next Steps: Check out our Tutorials section for more C# guides!