Code Evolution Playground

Boilerplate Evolution

See the same concept implemented across multiple C# versions. Witness 25 years of boilerplate reduction.

1. Data Models and DTOs

See the same model evolve from verbose property patterns to concise immutable contracts.

C# 1.0Step 1
1public class User
2{
3 private string _name;
4 public string Name { get { return _name; } set { _name = value; } }
5}

Early versions required explicit backing fields and verbose property blocks.

C# 3.0Step 2
1public class User
2{
3 public string Name { get; set; }
4}

Auto-implemented properties removed repetitive boilerplate for common property patterns.

C# 9.0Step 3
1public record User(string Name);

Records introduced positional syntax for ultra-concise, value-based immutable modeling.

C# 12Step 4
1public class UserService(IDbConnection db)
2{
3 public User GetUser(int id) => db.Query<User>(id);
4}

Primary constructors extended to standard classes, completely eliminating constructor bodies and explicit field assignments for dependencies.

C# 14Step 5
1public class User
2{
3 public string Name
4 {
5 get => field;
6 set => field = value?.Trim() ?? throw new ArgumentNullException(nameof(value));
7 }
8}

The field keyword lets properties add validation or transformation logic while still using compiler-generated backing storage.

4 evolution examples · Click an example above to switch