The C# compiler complains about the following code containing new protected member declared in struct. What is the problem?
struct Foo {
protected Object _bar;
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Because this is a struct, it cannot be overridden. It seems the C# compiler wants sealed types like structs to use the ‘private’ keyword rather than the ‘protected’ keyword, even though functionally there isn’t any difference. Use this instead: