Lecture overview -- Keyboard shortcut: 'u'  Previous page: Value Types [Section] -- Keyboard shortcut: 'p'  Next page: Illustration of variables of value 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 8 : 29
Object-oriented Programming in C#
Reference types, Value types, and Patterns
Value types

Value types stand as a contrast to reference types. There are dramatic difference between the use of value types and reference types in C#.

A variable of value type contains its value

The values are allocated on the method stack or within objects on the heap

Variables of value types are dealt with by use of so-called value semantics

Use of value types simplifies the management of short-lived data

  • Value semantics

    • Assignment, call-by-value parameter passing, and return copy entire values

  • The method stack

    • The memory area where short-lived data is allocated

      • Parameters and local variables

    • Allocation takes place when an operation, such as a method, is called

    • Deallocation takes place when the operation returns