Search code examples
c#c++access-levels

Access levels in C#


Quick simple questions,

Is there any way to declare the access level of more then one variable or method in C# as in C++?

Aswell, is it the same in C# as in C++ where the members of a struct are, if not defined, public and the members of a class are private?

Regards, Alex


Solution

  • 1.) No: Each variable is declared separately and may be qualified with a member access modifier. Exceptions are variables of the same type which can share a type and member access modifier.

    2.) No: The same rules as for classes apply - by default members are private if no access modifier is specified, big difference is that struct is a value type and not a reference type.