Programming in C# Properties

Slides:



Advertisements
Similar presentations
Generics Programming in C# Generics CSE 494R (proposed course for 459 Programming in C#) Prof. Roger Crawfis.
Advertisements

EC-241 Object-Oriented Programming
Attributes Programming in C# Attributes CSE 494R (proposed course for 459 Programming in C#) Prof. Roger Crawfis.
Equality Programming in C# Equality CSE 494R (proposed course for 459 Programming in C#) Prof. Roger Crawfis.
 In inheritance the child (subclass) chooses its parent (superclass)  Remember - only public or “protected” methods and variables are inherited  Should.
CSE 2501 Review Declaring a variable allocates space for the type of datum it is to store int x; // allocates space for an int int *px; // allocates space.
1 Modularity In “C”. 2 General Syntax data_type function_Name (parameter list) { … return expression; // return output } Body of the function is a compound.
Aspect-Oriented Software Development (AOSD) Tutorial #3 AspectJ - continued.
Object-Oriented Programming in C# Object-Oriented CSE 668 Prof. Roger Crawfis.
1 Using Classes Object-Oriented Programming Using C++ Second Edition 5.
Using Classes Object-Oriented Programming Using C++ Second Edition 5.
Extension Methods Programming in C# Extension Methods CSE Prof. Roger Crawfis.
Data Binding to Controls Programming in C# Data Binding to Controls CSE 494R (proposed course for 459 Programming in C#) Prof. Roger Crawfis.
Copyright 2008 by Pearson Education Building Java Programs Chapter 8 Lecture 8-2: Constructors and Encapsulation reading: self-checks: #10-17.
Copyright 2008 by Pearson Education Building Java Programs Chapter 8 Lecture 8-3: Encapsulation, this reading: self-checks: #13-17 exercises:
Delegates Programming in C# Delegates CSE 494R (proposed course for 459 Programming in C#) Prof. Roger Crawfis.
Introduction To Classes Chapter Procedural And Object Oriented Programming Procedural programming focuses on the process/actions that occur in a.
CS1010E Programming Methodology Tutorial 4 Modular Programming with Functions C14,A15,D11,C08,C11,A02.
PROGRAMMING IN C#. Collection Classes (C# Programming Guide) The.NET Framework provides specialized classes for data storage and retrieval. These classes.
Polymorphism, Virtual Methods and Interfaces Version 1.1.
Computer Engineering 2 nd Semester Dr. Rabie A. Ramadan 3.
February 28, 2005 Introduction to Classes. Object Oriented Programming An object is a software bundle of related variables and methods. Software objects.
Events Programming in C# Events CSE 494R (proposed course for 459 Programming in C#) Prof. Roger Crawfis.
AP Java Ch. 4 Review Question 1  Java methods can return only primitive types (int, double, boolean, etc).
Arrays and Indexers Programming in C# Arrays and Indexers CSE 494R (proposed course for 459 Programming in C#) Prof. Roger Crawfis.
C LANGUAGE UNIT 3. UNIT 3 Arrays Arrays – The concept of array – Defining arrays – Initializing arrays.
REEM ALAMER REVISION FOR C LANGUAGE COURSE. OUTPUTS int main (void) { int C1, C2; int *p1, *p2; C1 = 8; p1 = &C1; C2 = *p1 / 2 + 5; p2 = &C2; printf ("C1.
Object-Oriented Programming Using C++ Third Edition Chapter 7 Using Classes.
Memory Management.
Inner Classes.
Objects Real and Java COMP T1 3
Module 9: Memory and Resource Management
APPENDIX a WRITING SUBROUTINES IN C
Introduction to Linked Lists
Review What is an object? What is a class?
2.7 Inheritance Types of inheritance
Realizing Concurrency using the thread model
Programming in C# Object-Oriented
2.2 Defining Classes Part 2 academy.zariba.com.
Array Array is a variable which holds multiple values (elements) of similar data types. All the values are having their own index with an array. Index.
Structs.
Object-Oriented Programming Using C++
– Introduction to Object Technology
Methods The real power of an object-oriented programming language takes place when you start to manipulate objects. A method defines an action that allows.
Introduction to Linked Lists
Creating and Using Classes
CSC 113 Tutorial QUIZ I.
Classes and Data Abstraction
Enumerations & Annotations
Properties 7: Properties Programming C# © 2003 DevelopMentor, Inc.
Enumerations & Annotations
Programming in C# Comparison (Sorting)
CISC124 Assignment 4 on Inheritance due next Monday, the 12th at 7pm.
Realizing Concurrency using the thread model
Topic 28 classes and objects, part 2
Realizing Concurrency using the thread model
Review: Classes, Inheritance, and Collections
Building Java Programs
Enumerations & Annotations
Lecture 8: Complex Linked List Code reading: 16.2 – 16.3
Realizing Concurrency using the thread model
Developing Java Applications with NetBeans
Developing Java Applications with NetBeans
Chapter 11 Inheritance and Encapsulation and Polymorphism
Constructors and Deconstructor
Automation and IDispatch
Chapter 11 Classes.
Building Java Programs
Topic 29 classes and objects, part 3
Introduction to Classes and Objects
Presentation transcript:

Programming in C# Properties CSE 494R (proposed course for 459 Programming in C#) Prof. Roger Crawfis

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.

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.

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; }