New protected member declared in structure

The C # compiler complains about the following code containing new protected member declared in struct . What is the problem?

 struct Foo { protected Object _bar; } 
+4
source share
3 answers

Since this is a structure, it cannot be redefined. It seems that the C # compiler wants grouped types, such as structs, to use the keyword 'private' rather than the keyword 'protected', although functionally there is no difference. Use this instead:

 struct Foo { private Object _bar; } 
+1
source

From MSDN Docs :

 A struct cannot be abstract and is always implicitly sealed. 

It looks like C # wants you to use "private" instead of protected.

+6
source

Structures are implicitly sealed, so you cannot create descendants in any way, and a protected modifier means that only an instance of this type and all instances of derived types have access to it.

+2
source

All Articles