360 likes | 471 Vues
C# Programming. Fundamentals of Object-Oriented Programming Introducing Microsoft .NET Overview of C# Using Value-Type variables Statements and Exceptions Methods and Parameters Strings Arrays and Collections C# and Object Oriented Programming Using Reference-Type Variables
E N D
C# Programming • Fundamentals of Object-Oriented Programming • Introducing Microsoft .NET • Overview of C# • Using Value-Type variables • Statements and Exceptions • Methods and Parameters • Strings Arrays and Collections • C# and Object Oriented Programming • Using Reference-Type Variables • Creating and Destroying Objects • inheritance in C# • Aggregations, Namespaces and Advance Scope • Operators, Delegates and Events • Properties and Indexers
Fundamentals of Object-Oriented Programming • What is OOP • Objects vs. Classes • Instantiation • Encapsulation • Inheritance • Polymorphism
What is OOP • 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
Objects vs. Classes Object MyHouseAn Instance of HouseOfFun Class HouseOfFunA blue print of the HouseOfFun house. Object MyHouseAn Instance of HouseOfFun Object YelloHouse[0]An Instance of HouseOfFun Object YelloHouse[1]An Instance of HouseOfFun
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() { // calculationjust for this sample return (DateTime.Now.Year - buildYear); } }
Instantiation class mainClass { static void Main( ) { HouseOfFun myHouse = new HouseOfFun("Tel Aviv",2,1963); Console.WriteLine(myHouse.calcHouseAge()); } }
Encapsulation • The ability of an object to hide its internal data and methods, making only the intended parts of the object programmatically accessible. • C# • Public • Private • protected
Inheritance • 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 • speeds up program development; • ensures an inherent validity (what works and is consistent about the class will also work for the subclass).
Polymorphism • 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.
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 } }
Encapsulation, Inheritance, Polymorphism - 2/3FullTimeTeacher 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 • } • }
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); } } }
Introducing Microsoft .NET • The .NET Framework • The Common Language Runtime • The .NET Framework Class Libraries • Microsoft Intermediate Language and the Jitters • Unified Type System • Metadata and Reflection
The .NET Framework ASP.NET Windows Forms Data and XML Base Classes Common Language Runtime
The Common Language Runtime Common Type System Intermediate Language to Native Code Compilers ExecutionSupport Security GC, Stack Walk, Code Manager Class Loader & Memory Layout
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
Overview of C# • Structure of a c# program • Basic Input/Output Operations • Recommended Practices • Compiling Running and Debugging
Using Value-Type variables • Common Type System • Naming Variables • Using Built-in Data Types • Compound Assignment • Increment and Decrement • Creating User Defined Data Types • Converting Data Types
Statements and Exceptions • Selection Statements • Iteration Statements • Jump Statements • Handling Basic Exceptions • Raising Exceptions
Methods and Parameters • Methods • Parameters • Overload Methods
Strings Arrays and Collections • Strings • Creating Arrays • Using Arrays • Collections • .NET Framework Arrays • .Net Framework Collections • working with Strings, Enumerators and Collections
C# and Object Oriented Programming • Creating and using Classes
Using Reference-Type Variables • Reference-Type Variables • Common Reference Types • The Object Hierarchy • Namespaces in the .Net Framework • Data Conversions • Type-Safe Casting
Creating and Destroying Objects • Constructors • Initializing Data • Objects and Memory • Destructors
inheritance in C# • Deriving Classes • Implementing Methods • Sealed Classes • Interfaces • Abstract Classes
Aggregations, Namespaces and Advance Scope • Using internal classes, Methods and Data • Using Aggregation • Using Namespaces • Using Modules and Assemblies
Operators, Delegates and Events • Operators • Operator Overloading • Delegates • Events • When to use Delegates, Events and Interfaces
Properties and Indexers • properties • Indexers
C# Advance • Attributes • The SDK Tools
Attributes • Overview of attributes • Defining Custom Attributes • Retrieving Attributes Values
The SDK Tools • Configuration and Deployment Tools • Debugging Tools • Security Tools and Utilities • General Tools