Roadmap › C# Language — Basics to Advanced › Module: Modern C# and Reflection
Lessons in this course (38)

38. What's new in C# 12, 13 and 14

AdvancedLowLesson 38 of 38
csharp
// C# 12 — primary constructors and collection expressions
public class OrderService(IOrderRepo repo, ILogger<OrderService> log)
{
    public Task<Order?> Get(int id) => repo.FindAsync(id);
}
int[] a = [1, 2, 3];

// C# 13 — params collections and the Lock type
void Log(params ReadOnlySpan<string> parts) { }
Lock gate = new();

// C# 14 — extension members, field keyword, null-conditional assignment
public static class EnumerableExtensions
{
    extension<T>(IEnumerable<T> source)
    {
        public bool IsEmpty => !source.Any();          // extension PROPERTY
    }
}
customer?.Address = newAddress;                         // assigns only if customer is not null