Download presentation
Presentation is loading. Please wait.
Published byAnnis Shaw Modified over 9 years ago
1
C# Programming Fundamentals of Object-Oriented Programming Fundamentals of Object-Oriented Programming Introducing Microsoft.NET Introducing Microsoft.NET Overview of C# Overview of C# Using Value-Type variables Using Value-Type variables Statements and Exceptions Statements and Exceptions Methods and Parameters Methods and Parameters Strings Arrays and Collections Strings Arrays and Collections C# and Object Oriented Programming C# and Object Oriented Programming Using Reference-Type Variables Using Reference-Type Variables Creating and Destroying Objects Creating and Destroying Objects inheritance in C# inheritance in C# Aggregations, Namespaces and Advance Scope Aggregations, Namespaces and Advance Scope Operators, Delegates and Events Operators, Delegates and Events Properties and Indexers Properties and Indexers
2
Fundamentals of Object-Oriented Programming What is OOP What is OOP Objects vs. Classes Objects vs. Classes Instantiation Instantiation Encapsulation Encapsulation Inheritance Inheritance Polymorphism Polymorphism
3
What is OOP Object-oriented programming (OOP) is a programming language model organized around "objects" rather than "actions" and data rather than logic. Object-oriented programming (OOP) is a programming language model organized around "objects" rather than "actions" and data rather than logic. The first step in OOP is to identify all the objects you want to manipulate and how they relate to each other The first step in OOP is to identify all the objects you want to manipulate and how they relate to each other
4
Objects vs. Classes Class HouseOfFun A blue print of the HouseOfFun house. Object MyHouse An Instance of HouseOfFun Object YelloHouse[0] An Instance of HouseOfFun Object MyHouse An Instance of HouseOfFun Object YelloHouse[1] An Instance of HouseOfFun
5
Objects vs. Classes public class HouseOfFun { public HouseOfFun(string city, int rooms, int buildYear) { this.city = city; this.rooms = rooms; this.buildYear = buildYear; } protected string city; protected int rooms; protected int buildYear; public int calcHouseAge() { // calculation just for this sample return (DateTime.Now.Year - buildYear); }
6
Instantiation class mainClass { static void Main( ) { HouseOfFun myHouse = new HouseOfFun("Tel Aviv",2,1963); Console.WriteLine(myHouse.calcHouseAge()); }
7
Encapsulation The ability of an object to hide its internal data and methods, making only the intended parts of the object programmatically accessible. The ability of an object to hide its internal data and methods, making only the intended parts of the object programmatically accessible. C# C# Public Public Private Private protected protected
8
Inheritance Subclass that is defined can inherit the definitions of one or more general classes. Subclass that is defined can inherit the definitions of one or more general classes. An object in a subclass need not carry generic definition of data and methods An object in a subclass need not carry generic definition of data and methods speeds up program development; speeds up program development; ensures an inherent validity (what works and is consistent about the class will also work for the subclass). ensures an inherent validity (what works and is consistent about the class will also work for the subclass).
9
Polymorphism Polymorphism gives you the ability to group objects that have a common base class and treat them consistently. Polymorphism gives you the ability to group objects that have a common base class and treat them consistently. Polymorphism allows you to extend or enhance your system without modifying or breaking existing code. Polymorphism allows you to extend or enhance your system without modifying or breaking existing code.
10
Encapsulation, Inheritance, Polymorphism Sample page 1/3: class with virtual method class Teacher { public Teacher(string firstName,string lastName,int practiceYears,double payRate) { this.firstName = firstName; this.lastName = lastName; this.practiceYears = practiceYears; this.payRate = payRate; } protected string firstName; protected string lastName; protected int practiceYears; protected double payRate; public virtual double CalculatePayment(int hourseWorked) { // do something return 1,000,000.00; // bogus value }
11
Encapsulation, Inheritance, Polymorphism - 2/3 FullTimeTeacher is derived from Teacher class FullTimeTeacher:Teacher { public FullTimeTeacher(string firstName,string lastName,int practiceYears,double payRate) :base (firstName,lastName, practiceYears,payRate) { } public override double CalculatePayment(int hourseWorked) {//do something } class PartTimeTeacher:Teacher { public FullTimeTeacher(string firstName,string lastName,int practiceYears,double payRate) :base (firstName,lastName, practiceYears,payRate) { } public override double CalculatePayment(int hourseWorked) {//do something }
12
Encapsulation, Inheritance, Polymorphism 3/3 - teachers group hold FullTimeTeacher & PartTimeTeacher - CalculatePayment code stays the same class PolymorphismSample { protected Teacher[] teachers; protected void LoadTeachers() { //in a real world situation we will use the database teachers = new Teacher[2]; teachers[0] = new FullTimeTeacher("Marta", "Kohen", 25, 2500.00); teachers[2] = new PartTimeTeacher("Bar", "Shalom", 40, 50.00); } protected void CalculatePayment() { foreach(Teacher tcr in teachers) { tcr.CalculatePayment(40); }
13
Introducing Microsoft.NET The.NET Framework The.NET Framework The Common Language Runtime The Common Language Runtime The.NET Framework Class Libraries The.NET Framework Class Libraries Microsoft Intermediate Language and the Jitters Microsoft Intermediate Language and the Jitters Unified Type System Unified Type System Metadata and Reflection Metadata and Reflection
14
The.NET Framework ASP.NETWindows Forms Data and XML Base Classes Common Language Runtime
15
The Common Language Runtime Common Type System GC, Stack Walk, Code Manager Class Loader & Memory Layout Intermediate Language to Native Code Compilers Execution Support Security
16
The.NET Framework Class Libraries.Net Class Libraries provides language interoperability. Sample: The Class shown in this class Browser System.Data.OleDb. OleDbConnection can be used by all the many.Net languages
17
Microsoft Intermediate Language and the Jitters
18
Unified Type System
19
Metadata and Reflection
20
Overview of C# Structure of a c# program Structure of a c# program Basic Input/Output Operations Basic Input/Output Operations Recommended Practices Recommended Practices Compiling Running and Debugging Compiling Running and Debugging
21
Using Value-Type variables Common Type System Common Type System Naming Variables Naming Variables Using Built-in Data Types Using Built-in Data Types Compound Assignment Compound Assignment Increment and Decrement Increment and Decrement Creating User Defined Data Types Creating User Defined Data Types Converting Data Types Converting Data Types
22
Statements and Exceptions Selection Statements Selection Statements Iteration Statements Iteration Statements Jump Statements Jump Statements Handling Basic Exceptions Handling Basic Exceptions Raising Exceptions Raising Exceptions
23
Methods and Parameters Methods Methods Parameters Parameters Overload Methods Overload Methods
24
Strings Arrays and Collections Strings Strings Creating Arrays Creating Arrays Using Arrays Using Arrays Collections Collections.NET Framework Arrays.NET Framework Arrays.Net Framework Collections.Net Framework Collections working with Strings, Enumerators and Collections working with Strings, Enumerators and Collections
25
C# and Object Oriented Programming Creating and using Classes Creating and using Classes
26
Using Reference-Type Variables Reference-Type Variables Reference-Type Variables Common Reference Types Common Reference Types The Object Hierarchy The Object Hierarchy Namespaces in the.Net Framework Namespaces in the.Net Framework Data Conversions Data Conversions Type-Safe Casting Type-Safe Casting
27
Creating and Destroying Objects Constructors Constructors Initializing Data Initializing Data Objects and Memory Objects and Memory Destructors Destructors
28
inheritance in C# Deriving Classes Deriving Classes Implementing Methods Implementing Methods Sealed Classes Sealed Classes Interfaces Interfaces Abstract Classes Abstract Classes
29
Aggregations, Namespaces and Advance Scope Using internal classes, Methods and Data Using internal classes, Methods and Data Using Aggregation Using Aggregation Using Namespaces Using Namespaces Using Modules and Assemblies Using Modules and Assemblies
30
Operators, Delegates and Events Operators Operators Operator Overloading Operator Overloading Delegates Delegates Events Events When to use Delegates, Events and Interfaces When to use Delegates, Events and Interfaces
31
Properties and Indexers properties properties Indexers Indexers
32
Review
33
C# Advance Attributes Attributes The SDK Tools The SDK Tools
34
Attributes Overview of attributes Overview of attributes Defining Custom Attributes Defining Custom Attributes Retrieving Attributes Values Retrieving Attributes Values
35
The SDK Tools Configuration and Deployment Tools Configuration and Deployment Tools Debugging Tools Debugging Tools Security Tools and Utilities Security Tools and Utilities General Tools General Tools
36
Review
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.