Lecture overview -- Keyboard shortcut: 'u'  Previous page: Reference Types [Section] -- Keyboard shortcut: 'p'  Next page: Illustration of variables of reference types -- Keyboard shortcut: 'n'  Lecture notes - all slides and notes together  slide -- Keyboard shortcut: 't'  Textbook -- Keyboard shortcut: 'v'  Help page about these notes  Alphabetic index  Course home  Page 2 : 29
Object-oriented Programming in C#
Reference types, Value types, and Patterns
Reference Types

Classes are reference types in C#. It is therefore important to understand this concept.

A class is a reference type

Objects instantiated from classes are accessed by references

The objects are allocated on the heap

Instances of classes are dealt with by use of so-called reference semantics

  • Reference semantics:

    • Assignment, parameter passing, and return manipulates references to objects

  • The heap:

    • The memory area where instances of classes are allocated

    • Allocation takes place when a class is instantiated

    • Deallocation takes place when the object no longer affects the program

      • In practice, when there are no references left to the object

      • By a separate thread of control called the garbage collector