Developer bit
The Evolution of C# Constructors
C# 12 introduces a new syntax to declare class constructors with Primary Constructors. That's why I thought that it's a good time to look back at the evolution of C# constructors. Starting from the most basic constructor that most of us are familiar with, to the newer variations that were added in latest the C# versions.
Person.tspublic class Person{public long Id { get; }public string Name { get; }public Person(int id, string name){Id = id;Name = name;}}
Person.tspublic class Person{public long Id { get; }public string Name { get; }public Person(int id, string name)=> (Id, Name) = (id, name);}
Person.tspublic class Person{public required long Id { get; init; }public required string Name { get; init; }}
Person.tspublic class Person(long id, string name){public long Id { get; } = id;public string Name { get; } = name;}
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!