Classes

A class represents the encapsulation of data and methods that act on that data. In C#, classes are considered reference types and, as such, instances of classes are allocated on the heap and managed by the GC. When an instance of a class is created, memory is allocated on the heap and the object is referenced counted. When the reference count for the object reaches zero, the GC will reclaim the memory area being used by the object and return that memory to the available memory pool.

Classes can contain fields, methods, events, properties, and nested classes. Classes also have the ability to inherit from another class and implement multiple interfaces.

Like structs, the default protection level for class members is private. Classes can ...

Get C# and the .NET Framework: The C++ Perspective 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.