C#C
C#11mo ago
6 replies
Faker

✅ required attribute vs [Required] annotation

Hello guys, I was just reading a bit about the required modifier and [Required] data annotation. From what I've understood, required make sure something is not null at compile time itself whereas the data annotation one make sure something is not null at runtime. Beside these 2, are there other differences? Also, I was wondering, why not just stick to required, are there any use cases where one is better than the other please.
Was this page helpful?