Lecture overview -- Keyboard shortcut: 'u'  Previous page: Properties - Tricky Use -- Keyboard shortcut: 'p'  Next page: Properties: Class Point with polar coordinates -- 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 7 : 29
Object-oriented Programming in C#
Data Access, Properties, and Methods
Properties in C#

Properties introduce getter and setter methods in C# - in a very convenient way. You can think of a property as a method. It is important to realize, however, that you cannot tell the difference between an activation of a property and use of a variable. An activation of a method M reveal itself by the required parentheses after M: M(...).

Properties allow indirect getting and setting of instance variables

We introduce properties by a number of examples.

On this page we provide a number of introductory examples of a Balance property of class BankAccount.

/user/normark/oop-csharp-1/sources/c-sharp/bank-account/bank-account-properties/bank-account-1.csA BankAccount class with a trivial Balance property together with Deposit and Withdraw methods. This program is explained


/user/normark/oop-csharp-1/sources/c-sharp/bank-account/bank-account-properties/accumulating-bank-account.csA BankAccount class with a Balance property - without a balance instance variable. This program is explained


/user/normark/oop-csharp-1/sources/c-sharp/bank-account/bank-account-properties/accumulating-app.csA client program. This program is explained


/user/normark/oop-csharp-1/sources/c-sharp/bank-account/bank-account-properties/accumulating-outputOutput from the client program.


/user/normark/oop-csharp-1/sources/c-sharp/bank-account/bank-account-properties/disciplined-bank-account.csA BankAccount class with a disciplined Balance property. This program is explained


/user/normark/oop-csharp-1/sources/c-sharp/bank-account/bank-account-properties/disciplined-app.csA client of the disciplined BankAccount. This program is explained


/user/normark/oop-csharp-1/sources/c-sharp/bank-account/bank-account-properties/disciplined-outputOutput of the this client.


Go to exerciseA funny BankAccount
Read more about this topic in the text book version of this material.