Encapsulation

Simply put, this means that the inner workings of the class (the implementation details) are not necessarily shared with outside code. Remember that we mentioned earlier that a class is something that you just want to use and expect it to work. The class exposes what it needs to to the calling code, but it maintains tight control over the inner workings it implements.

You can, therefore, hide the variables, properties, and methods by scoping them as private. This way, you protect the data contained inside the class from accidental corruption.

Get C# 7 and .NET Core 2.0 Blueprints 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.