Lecture overview -- Keyboard shortcut: 'u'  Previous page: Object Initialization via Properties -- Keyboard shortcut: 'p'  Next page: Indexers [Section] -- 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 11 : 29
Object-oriented Programming in C#
Data Access, Properties, and Methods
Summary of properties in C#

We mention and summarize some important properties of properties.


 modifiers return-type property-name{
  get {body-of-get}
  set {body-of-set}
}

The syntax of a C# property. Here we show both the getter and setter. At least one of them must be present.

  • Property characteristics

    • Provides for either read-only, write-only, or read-write access

    • Both instance and class (static) properties make sense

    • Property setting appears on the left of an assignment, and in ++ and --

    • Trivial properties can be defined "automatically"

    • Properties should be fast and without unnecessary side-effects

A C# property will often have the same name as a private data member

The name of the property is capitalized - the name of the data member is not

Naming conventions - pertain to coding style.