© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
10 replies
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:

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


Should it be this instead?:
public class A
{
  [Required]
  public required string Name { get; set; }
}
public class A
{
  [Required]
  public required string Name { get; set; }
}
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

EF Entity 'required' property
C#CC# / help
2y ago
records, with expression, required property
C#CC# / help
15mo ago
EF Core Model not-required property
C#CC# / help
4y ago
✅ Seed cannot be added because of required property ID
C#CC# / help
2y ago