Lecture overview -- Keyboard shortcut: 'u'  Previous page: Indirect data access -- Keyboard shortcut: 'p'  Next page: Properties [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 3 : 29
Object-oriented Programming in C#
Data Access, Properties, and Methods
Overview of data access in C#

Our interest is indirect data access. On this page we take a very broad look at data access, including direct access to data.

In C# the data of a class can be accessed in several different ways

  • Data access

    • Directly via public instance variables

      • Never do that!

    • Indirectly via properties

      • Clients cannot tell the difference between access via properties and direct access of instance variables

    • Indirectly via methods

      • Should be reserved for "calculations on objects"

    • Indirectly via indexers

      • Provides access by means of the notation known from traditional array indexing

    • Indirectly via overloaded operators

      • Provides access by means of the language-defined operator symbols