CHAPTER 13

image

Access Levels

Every class member has an accessibility level that determines where the member will be visible. There are five of them available in C#: public, protected, internal, protected internal and private. The default access level for members of a class is private.

Private access

All members regardless of access level are accessible in the class in which they are declared, the enclosing class. This is the only place where a private member can be accessed.

class MyBase{  // Unrestricted access  public int myPublic;    // Defining assembly or derived class  protected internal int myProtInt;    // Defining assembly  internal int ...

Get C# Quick Syntax Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.