C#C
C#2y ago
tama

✅ Required property

Hello there.

I am creating a class with some required properties. I have decorated them with the [Required] thing, however, it's still complaining. Are you supposed to have both [Required] and the required keyword? Example:

C#
public class A
{
  [Required]
  public string Name { get; set; }
}


Should it be this instead?:
C#
public class A
{
  [Required]
  public required string Name { get; set; }
}
Was this page helpful?