I want to allow internal required members in public class if have only internal constructors. #9075
Answered
by
iam3yal
ChanyaKushima
asked this question in
General
-
Proposal Details
Examplepublic class MyClass
{
internal required string MyRequiredProp { get; init; }
internal MyClass()
{
// Optionally set default values
}
internal MyClass(string value)
{
MyRequiredProp = value;
}
}
Currently, attempting to declare required members at a lower accessibility level than the class itself—while the class is public but has non-public constructors—leads to compiler error CS9032 in C#. This error indicates that the accessibility rules for required members are tied to the class's declared visibility rather than the actual accessibility of its constructors. |
Beta Was this translation helpful? Give feedback.
Answered by
iam3yal
Jan 19, 2025
Replies: 1 comment
Answer selected by
ChanyaKushima
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@ChanyaKushima #6435, #7618