C# 11 has introduced, required modifier, which can be used a below:
public required string FirstName { get; init; }
public required string LastName { get; init; }
[Required]
public required string FirstName { get; init; }
Just wanted to understand the difference between [Required] attribute and required modifier. Read the documentation but did not understand.
Tried reading documentation
[Required]
attribute is a data validation attribute which can be triggered during runtime,required
modifier is used to denote required property during initialization, it is explained quite well in the article - newdevsguide.com/2022/11/12/csharp-11-required-keyword – Karylkarylin