CSE459_CSharp_03_Properties

CSE459_CSharp_03_Properties - Properties Properties can be...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
Programming in C# Properties Properties CSE 494R (proposed course for 459 Programming in C#) Prof. Roger Crawfis
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Properties Typical pattern for accessing fields. private int x; public int GetX(); public void SetX(int newVal); Elevated into the language: private int count; public int Count { get { return count; } set { count = value ; } } Typically there is a backing-store , but not always.
Background image of page 2
Properties Using a property is more like using a public field than calling a function: FooClass foo; int count = foo.Count; // calls get int count = foo.count; // compile error The compiler automatically generates the routine or in-lines the code.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 4
Background image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Properties Properties can be used in interfaces Can have three types of a property read-write, read-only, write-only More important with WPF and declarative programming. // read-only property declaration // in an interface. int ID { get ; }; Automatic Properties C# 3.0 added a shortcut version for the common case (or rapid prototyping) where my get and set just read and wrote to a backing store data element. Avoids having to declare the backing store. The compiler generates it for you implicitly. public decimal CurrentPrice { get ; set ; }...
View Full Document

This note was uploaded on 02/27/2012 for the course CSE 459.24 taught by Professor Crawfis during the Winter '11 term at Ohio State.

Page1 / 5

CSE459_CSharp_03_Properties - Properties Properties can be...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online