SlideShare a Scribd company logo
Software Development  Training Program Zeeshan Hanif Zeeshan Hanif
DotNet 3.5-101 Lecture 6 Zeeshan Hanif Zeeshan Hanif [email_address] [email_address]
Object Oriented Programming Object-oriented programming focuses on the development of self-contained software components, called  objects . Objects in Everyday Life Objects are key to understanding object oriented technology. You can look around you now and see many examples of real-world objects: dog,  car, television set, bicycle. Zeeshan Hanif
Object in Everyday Life All these real world objects have two characteristics:  state  and  behavior . For example car have states (current gear, number of gears, color, number of wheels) and behavior (braking, accelerating, slowing down, changing gears ) etc. Zeeshan Hanif
Object in Programming Objects are useful in programming because you can set up a software model of real-world system. Software objects too have state and behavior. A software object maintains its state in one or more  variable . A software object implements its behavior with  methods . An  object  is a software bundle of variables and related methods. Zeeshan Hanif
Class and Object In the real world, we often have many objects of the same kind For example my car is just one of many cars in the world Using object-oriented terminology, we say that my car object is an instance of the class of objects known as cars. Zeeshan Hanif
Class and Object Cars have some state (current gear, one engine, four wheels) and behavior (change gears, brake) in common. However, each car’s state is independent and can be different from that of other cars. A construction company have a blueprint of house but my house is created on the basis of that blueprint. So that blueprint is class and my house is object of that class Zeeshan Hanif
Class and Object A software (blueprint or map) for objects is called a  class. You can also say that a class is a template After you've created the car class, you can create any number of car objects from the class. Each instance gets its own copy of all the instance variables defined in the class.  Zeeshan Hanif
Example public class Car { public int wheels; public string color; public int noOfSeats; } Zeeshan Hanif
Class Members Instance and Static Fields Instance variables Each object of the class will have its own copy of each of the instance variables that appear in the class definition Static variables A given class will only have one copy of each of its class variable. The class variable exists even if no objects of the class have been created Zeeshan Hanif
Zeeshan Hanif Class Definition public class Car{ public static int wheel; public string color; public bool isAutomatic; } Car1 Color isAutomatic Car2 Color isAutomatic Each object gets its own copy Shared between all objects Car.Wheel Car objects wheel
Class Members Instance and Static Methods Unlike variables there is not any separate copy for each methods. Therefore, instance and static methods are stored only once, and associated with the class as a whole. Instance variable and methods can not be called from static methods Zeeshan Hanif
Class Members Zeeshan Hanif c1 instance Instance Fields color c2 instance Instance Fields color All Methods NoOfWheels() Start() Car Class Static Fields wheel
Defining Methods Zeeshan Hanif public int start(int a, string b,......) { // Executable code } The type of the value to be returned Name of the method The specification of the parameters for the method. If the method has no parameters, leave the parentheses empty Access modifier This is called the body of method Method Signature
Defining Methods Parameter List Value Parameters Reference Parameters Output Parameters Class Parameters Structure Parameters Argument Value Passing Zeeshan Hanif
Encapsulation A powerful benefit of encapsulation is the hiding of implementation details from other objects. This means that the internal portion (variables) of an object has more limited visibility than the external portion (methods). This will protect the internal portion against unwanted external access.  Zeeshan Hanif
Properties The encapsulation principle leads us to typically store data in private fields and provide access to this data through public accessor methods that allow us to set and get values So we have to create two methods such as GetData() and SetData()  C# provides a special property syntax that simplifies this process Zeeshan Hanif
Properties syntax Zeeshan Hanif public class Student { private string name; public string  GetName () { return name; } public void  SetName (string a) { name = a; } } public class Student  { private string name; public string Name  { get { return name; } set { name = value; } }} Using Property   Using Methods
Method Overloading If you want to use same method for different type of data processing then you have to overload your method That is two or more method have same names but different signature Zeeshan Hanif
Method Overloading Two methods have the same signature if they have the same number of parameters, the parameters have the same data types, and the parameters have the same modifiers (none, ref, out). The return type does not contribute to defining the signature of a method. Zeeshan Hanif
Example public class MyMath{ public int FindMax( int a, int b ){ return a>b? a : b; } public string FindMax( string a, string b ){ return a.CompareTo(b) >= 0 ? a : b; } } Zeeshan Hanif
this Every instance method has a variable with name this which refers to the current object of which method is being called. It is called implicitly by the compiler when your method refer to any instance variable of the class Zeeshan Hanif
Example public class Human { private string name; public Human(string name) { this.name  = name; } public void setName(string name){ this.name  = name; } } Zeeshan Hanif
Constructor The purpose of a constructor is to provide you with the means of initializing the instance variables uniquely for the object that is being created. Constructor is special method with the name of Class and automatically called when an object is created. Zeeshan Hanif
Constructor Constructor is special method that is automatically called when an object is created. A Constructor: has no return type Has the same name as the class Usually have public access May take parameters which are passed when invoking new Zeeshan Hanif
Constructor public class Human { private string name; private string address; private int age; public Human(string a, string b, int c) { name = a; address = b; age = c; } } Zeeshan Hanif
Multiple Constructor Default constructor More then one Constructor just like method overloading Duplicating objects using constructor Calling constructor from constructor(eg. This) Static constructor Zeeshan Hanif
Constant and Readonly Fields const If a field is declared as const then it is not really a variable at all. It is treated as a fixed hard coded value in the program. const variable is implicitly static and its value can not be changed Zeeshan Hanif
const public class Car { public  const  int wheel = 4; public void ChangeWheel(){ wheel= 5;  // compile-time error } } Zeeshan Hanif
readonly readonly keyword gives a bit more flexibility than const, allowing for the case in which you might want a field be to constant, but need to carry out some calculations to determine its initial value. readonly can be static or non-static but once readonly variable is initialize it can not be changed Zeeshan Hanif
readonly public class RegistrationForm { public  readonly  DateTime time; public RegistrationForm() { // one time initialization time = DateTime.Now;   // now this can not be changed }  } Zeeshan Hanif
Variable length parameter Lists When you to pass undefined number of parameters to any method then you use params keyword You can pass any number of parameter and it treats it as array. WriteLine method is an example Zeeshan Hanif
params public int FindMax( params int[] a ){ int max = 0; for(int i=0;i< a.Lenght ;i++){ if(a[i] > max) max = a[i];  } return max; } Calling this method like this FindMax( 4,5,6,7,5,3,2,3,3,4,3 ); Zeeshan Hanif
Ad

More Related Content

What's hot (18)

C++ classes
C++ classesC++ classes
C++ classes
imhammadali
 
[OOP - Lec 18] Static Data Member
[OOP - Lec 18] Static Data Member[OOP - Lec 18] Static Data Member
[OOP - Lec 18] Static Data Member
Muhammad Hammad Waseem
 
08 class and object
08   class and object08   class and object
08 class and object
dhrubo kayal
 
Data members and member functions
Data members and member functionsData members and member functions
Data members and member functions
Marlom46
 
3. Data types and Variables
3. Data types and Variables3. Data types and Variables
3. Data types and Variables
Nilesh Dalvi
 
Classes&amp;objects
Classes&amp;objectsClasses&amp;objects
Classes&amp;objects
M Vishnuvardhan Reddy
 
10. Introduction to Datastructure
10. Introduction to Datastructure10. Introduction to Datastructure
10. Introduction to Datastructure
Nilesh Dalvi
 
Chapter2 array of objects
Chapter2 array of objectsChapter2 array of objects
Chapter2 array of objects
Mahmoud Alfarra
 
An introduction to functional programming with Swift
An introduction to functional programming with SwiftAn introduction to functional programming with Swift
An introduction to functional programming with Swift
Fatih Nayebi, Ph.D.
 
class and objects
class and objectsclass and objects
class and objects
Payel Guria
 
Reviewing OOP Design patterns
Reviewing OOP Design patternsReviewing OOP Design patterns
Reviewing OOP Design patterns
Olivier Bacs
 
‫Chapter3 inheritance
‫Chapter3 inheritance‫Chapter3 inheritance
‫Chapter3 inheritance
Mahmoud Alfarra
 
[OOP - Lec 04,05] Basic Building Blocks of OOP
[OOP - Lec 04,05] Basic Building Blocks of OOP[OOP - Lec 04,05] Basic Building Blocks of OOP
[OOP - Lec 04,05] Basic Building Blocks of OOP
Muhammad Hammad Waseem
 
Final keyword in java
Final keyword in javaFinal keyword in java
Final keyword in java
Lovely Professional University
 
CPP15 - Inheritance
CPP15 - InheritanceCPP15 - Inheritance
CPP15 - Inheritance
Michael Heron
 
Standard Template Library
Standard Template LibraryStandard Template Library
Standard Template Library
Nilesh Dalvi
 
12. Stack
12. Stack12. Stack
12. Stack
Nilesh Dalvi
 
Chapter 2 java
Chapter 2 javaChapter 2 java
Chapter 2 java
Ahmad sohail Kakar
 
08 class and object
08   class and object08   class and object
08 class and object
dhrubo kayal
 
Data members and member functions
Data members and member functionsData members and member functions
Data members and member functions
Marlom46
 
3. Data types and Variables
3. Data types and Variables3. Data types and Variables
3. Data types and Variables
Nilesh Dalvi
 
10. Introduction to Datastructure
10. Introduction to Datastructure10. Introduction to Datastructure
10. Introduction to Datastructure
Nilesh Dalvi
 
Chapter2 array of objects
Chapter2 array of objectsChapter2 array of objects
Chapter2 array of objects
Mahmoud Alfarra
 
An introduction to functional programming with Swift
An introduction to functional programming with SwiftAn introduction to functional programming with Swift
An introduction to functional programming with Swift
Fatih Nayebi, Ph.D.
 
class and objects
class and objectsclass and objects
class and objects
Payel Guria
 
Reviewing OOP Design patterns
Reviewing OOP Design patternsReviewing OOP Design patterns
Reviewing OOP Design patterns
Olivier Bacs
 
[OOP - Lec 04,05] Basic Building Blocks of OOP
[OOP - Lec 04,05] Basic Building Blocks of OOP[OOP - Lec 04,05] Basic Building Blocks of OOP
[OOP - Lec 04,05] Basic Building Blocks of OOP
Muhammad Hammad Waseem
 
Standard Template Library
Standard Template LibraryStandard Template Library
Standard Template Library
Nilesh Dalvi
 

Viewers also liked (8)

C Sharp Jn (1)
C Sharp Jn (1)C Sharp Jn (1)
C Sharp Jn (1)
jahanullah
 
C Sharp Jn (5)
C Sharp Jn (5)C Sharp Jn (5)
C Sharp Jn (5)
jahanullah
 
C Sharp Jn (6)
C Sharp Jn (6)C Sharp Jn (6)
C Sharp Jn (6)
jahanullah
 
C Sharp Jn (3)
C Sharp Jn (3)C Sharp Jn (3)
C Sharp Jn (3)
jahanullah
 
C Sharp Jn (2)
C Sharp Jn (2)C Sharp Jn (2)
C Sharp Jn (2)
jahanullah
 
C Sharp Jn
C Sharp JnC Sharp Jn
C Sharp Jn
jahanullah
 
DOCILITY (IMPRONTA) FULL
DOCILITY (IMPRONTA) FULLDOCILITY (IMPRONTA) FULL
DOCILITY (IMPRONTA) FULL
Miss Paulina (Paulina Rodríguez)
 
The Six Highest Performing B2B Blog Post Formats
The Six Highest Performing B2B Blog Post FormatsThe Six Highest Performing B2B Blog Post Formats
The Six Highest Performing B2B Blog Post Formats
Barry Feldman
 
Ad

Similar to C Sharp Jn (5) (20)

Classes_python.pptx
Classes_python.pptxClasses_python.pptx
Classes_python.pptx
RabiyaZhexembayeva
 
java
javajava
java
jent46
 
Java is an Object-Oriented Language
Java is an Object-Oriented LanguageJava is an Object-Oriented Language
Java is an Object-Oriented Language
ale8819
 
Classes2
Classes2Classes2
Classes2
phanleson
 
Ap Power Point Chpt4
Ap Power Point Chpt4Ap Power Point Chpt4
Ap Power Point Chpt4
dplunkett
 
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
vekariyakashyap
 
java tr.docx
java tr.docxjava tr.docx
java tr.docx
harishkuna4
 
Oop features java presentationshow
Oop features java presentationshowOop features java presentationshow
Oop features java presentationshow
ilias ahmed
 
Drupaljam xl 2019 presentation multilingualism makes better programmers
Drupaljam xl 2019 presentation   multilingualism makes better programmersDrupaljam xl 2019 presentation   multilingualism makes better programmers
Drupaljam xl 2019 presentation multilingualism makes better programmers
Alexander Varwijk
 
Java 8 presentation
Java 8 presentationJava 8 presentation
Java 8 presentation
Van Huong
 
Java basics
Java basicsJava basics
Java basics
Shivanshu Purwar
 
Chap2 class,objects
Chap2 class,objectsChap2 class,objects
Chap2 class,objects
raksharao
 
Android Training (Java Review)
Android Training (Java Review)Android Training (Java Review)
Android Training (Java Review)
Khaled Anaqwa
 
Ch. 6 -Static Class Members.ppt programming
Ch. 6 -Static Class Members.ppt programmingCh. 6 -Static Class Members.ppt programming
Ch. 6 -Static Class Members.ppt programming
adamjarrah2006
 
JavaScript - Programming Languages course
JavaScript - Programming Languages course JavaScript - Programming Languages course
JavaScript - Programming Languages course
yoavrubin
 
9781439035665 ppt ch07
9781439035665 ppt ch079781439035665 ppt ch07
9781439035665 ppt ch07
Terry Yoast
 
Hemajava
HemajavaHemajava
Hemajava
SangeethaSasi1
 
classes-objects in oops java-201023154255.pptx
classes-objects in oops java-201023154255.pptxclasses-objects in oops java-201023154255.pptx
classes-objects in oops java-201023154255.pptx
janetvidyaanancys
 
Basic concept of class, method , command line-argument
Basic concept of class, method , command line-argumentBasic concept of class, method , command line-argument
Basic concept of class, method , command line-argument
Suresh Mohta
 
The Ring programming language version 1.5.4 book - Part 74 of 185
The Ring programming language version 1.5.4 book - Part 74 of 185The Ring programming language version 1.5.4 book - Part 74 of 185
The Ring programming language version 1.5.4 book - Part 74 of 185
Mahmoud Samir Fayed
 
Java is an Object-Oriented Language
Java is an Object-Oriented LanguageJava is an Object-Oriented Language
Java is an Object-Oriented Language
ale8819
 
Ap Power Point Chpt4
Ap Power Point Chpt4Ap Power Point Chpt4
Ap Power Point Chpt4
dplunkett
 
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
vekariyakashyap
 
Oop features java presentationshow
Oop features java presentationshowOop features java presentationshow
Oop features java presentationshow
ilias ahmed
 
Drupaljam xl 2019 presentation multilingualism makes better programmers
Drupaljam xl 2019 presentation   multilingualism makes better programmersDrupaljam xl 2019 presentation   multilingualism makes better programmers
Drupaljam xl 2019 presentation multilingualism makes better programmers
Alexander Varwijk
 
Java 8 presentation
Java 8 presentationJava 8 presentation
Java 8 presentation
Van Huong
 
Chap2 class,objects
Chap2 class,objectsChap2 class,objects
Chap2 class,objects
raksharao
 
Android Training (Java Review)
Android Training (Java Review)Android Training (Java Review)
Android Training (Java Review)
Khaled Anaqwa
 
Ch. 6 -Static Class Members.ppt programming
Ch. 6 -Static Class Members.ppt programmingCh. 6 -Static Class Members.ppt programming
Ch. 6 -Static Class Members.ppt programming
adamjarrah2006
 
JavaScript - Programming Languages course
JavaScript - Programming Languages course JavaScript - Programming Languages course
JavaScript - Programming Languages course
yoavrubin
 
9781439035665 ppt ch07
9781439035665 ppt ch079781439035665 ppt ch07
9781439035665 ppt ch07
Terry Yoast
 
classes-objects in oops java-201023154255.pptx
classes-objects in oops java-201023154255.pptxclasses-objects in oops java-201023154255.pptx
classes-objects in oops java-201023154255.pptx
janetvidyaanancys
 
Basic concept of class, method , command line-argument
Basic concept of class, method , command line-argumentBasic concept of class, method , command line-argument
Basic concept of class, method , command line-argument
Suresh Mohta
 
The Ring programming language version 1.5.4 book - Part 74 of 185
The Ring programming language version 1.5.4 book - Part 74 of 185The Ring programming language version 1.5.4 book - Part 74 of 185
The Ring programming language version 1.5.4 book - Part 74 of 185
Mahmoud Samir Fayed
 
Ad

Recently uploaded (20)

AI x Accessibility UXPA by Stew Smith and Olivier Vroom
AI x Accessibility UXPA by Stew Smith and Olivier VroomAI x Accessibility UXPA by Stew Smith and Olivier Vroom
AI x Accessibility UXPA by Stew Smith and Olivier Vroom
UXPA Boston
 
Slack like a pro: strategies for 10x engineering teams
Slack like a pro: strategies for 10x engineering teamsSlack like a pro: strategies for 10x engineering teams
Slack like a pro: strategies for 10x engineering teams
Nacho Cougil
 
Top 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptx
Top 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptxTop 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptx
Top 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptx
mkubeusa
 
Building the Customer Identity Community, Together.pdf
Building the Customer Identity Community, Together.pdfBuilding the Customer Identity Community, Together.pdf
Building the Customer Identity Community, Together.pdf
Cheryl Hung
 
AI-proof your career by Olivier Vroom and David WIlliamson
AI-proof your career by Olivier Vroom and David WIlliamsonAI-proof your career by Olivier Vroom and David WIlliamson
AI-proof your career by Olivier Vroom and David WIlliamson
UXPA Boston
 
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Safe Software
 
Zilliz Cloud Monthly Technical Review: May 2025
Zilliz Cloud Monthly Technical Review: May 2025Zilliz Cloud Monthly Technical Review: May 2025
Zilliz Cloud Monthly Technical Review: May 2025
Zilliz
 
IT488 Wireless Sensor Networks_Information Technology
IT488 Wireless Sensor Networks_Information TechnologyIT488 Wireless Sensor Networks_Information Technology
IT488 Wireless Sensor Networks_Information Technology
SHEHABALYAMANI
 
Smart Investments Leveraging Agentic AI for Real Estate Success.pptx
Smart Investments Leveraging Agentic AI for Real Estate Success.pptxSmart Investments Leveraging Agentic AI for Real Estate Success.pptx
Smart Investments Leveraging Agentic AI for Real Estate Success.pptx
Seasia Infotech
 
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
João Esperancinha
 
The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...
The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...
The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...
SOFTTECHHUB
 
Design pattern talk by Kaya Weers - 2025 (v2)
Design pattern talk by Kaya Weers - 2025 (v2)Design pattern talk by Kaya Weers - 2025 (v2)
Design pattern talk by Kaya Weers - 2025 (v2)
Kaya Weers
 
Agentic Automation - Delhi UiPath Community Meetup
Agentic Automation - Delhi UiPath Community MeetupAgentic Automation - Delhi UiPath Community Meetup
Agentic Automation - Delhi UiPath Community Meetup
Manoj Batra (1600 + Connections)
 
AI Agents at Work: UiPath, Maestro & the Future of Documents
AI Agents at Work: UiPath, Maestro & the Future of DocumentsAI Agents at Work: UiPath, Maestro & the Future of Documents
AI Agents at Work: UiPath, Maestro & the Future of Documents
UiPathCommunity
 
AsyncAPI v3 : Streamlining Event-Driven API Design
AsyncAPI v3 : Streamlining Event-Driven API DesignAsyncAPI v3 : Streamlining Event-Driven API Design
AsyncAPI v3 : Streamlining Event-Driven API Design
leonid54
 
Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?
Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?
Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?
Christian Folini
 
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
Ivano Malavolta
 
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
Lorenzo Miniero
 
Limecraft Webinar - 2025.3 release, featuring Content Delivery, Graphic Conte...
Limecraft Webinar - 2025.3 release, featuring Content Delivery, Graphic Conte...Limecraft Webinar - 2025.3 release, featuring Content Delivery, Graphic Conte...
Limecraft Webinar - 2025.3 release, featuring Content Delivery, Graphic Conte...
Maarten Verwaest
 
Q1 2025 Dropbox Earnings and Investor Presentation
Q1 2025 Dropbox Earnings and Investor PresentationQ1 2025 Dropbox Earnings and Investor Presentation
Q1 2025 Dropbox Earnings and Investor Presentation
Dropbox
 
AI x Accessibility UXPA by Stew Smith and Olivier Vroom
AI x Accessibility UXPA by Stew Smith and Olivier VroomAI x Accessibility UXPA by Stew Smith and Olivier Vroom
AI x Accessibility UXPA by Stew Smith and Olivier Vroom
UXPA Boston
 
Slack like a pro: strategies for 10x engineering teams
Slack like a pro: strategies for 10x engineering teamsSlack like a pro: strategies for 10x engineering teams
Slack like a pro: strategies for 10x engineering teams
Nacho Cougil
 
Top 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptx
Top 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptxTop 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptx
Top 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptx
mkubeusa
 
Building the Customer Identity Community, Together.pdf
Building the Customer Identity Community, Together.pdfBuilding the Customer Identity Community, Together.pdf
Building the Customer Identity Community, Together.pdf
Cheryl Hung
 
AI-proof your career by Olivier Vroom and David WIlliamson
AI-proof your career by Olivier Vroom and David WIlliamsonAI-proof your career by Olivier Vroom and David WIlliamson
AI-proof your career by Olivier Vroom and David WIlliamson
UXPA Boston
 
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Safe Software
 
Zilliz Cloud Monthly Technical Review: May 2025
Zilliz Cloud Monthly Technical Review: May 2025Zilliz Cloud Monthly Technical Review: May 2025
Zilliz Cloud Monthly Technical Review: May 2025
Zilliz
 
IT488 Wireless Sensor Networks_Information Technology
IT488 Wireless Sensor Networks_Information TechnologyIT488 Wireless Sensor Networks_Information Technology
IT488 Wireless Sensor Networks_Information Technology
SHEHABALYAMANI
 
Smart Investments Leveraging Agentic AI for Real Estate Success.pptx
Smart Investments Leveraging Agentic AI for Real Estate Success.pptxSmart Investments Leveraging Agentic AI for Real Estate Success.pptx
Smart Investments Leveraging Agentic AI for Real Estate Success.pptx
Seasia Infotech
 
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
Could Virtual Threads cast away the usage of Kotlin Coroutines - DevoxxUK2025
João Esperancinha
 
The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...
The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...
The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...
SOFTTECHHUB
 
Design pattern talk by Kaya Weers - 2025 (v2)
Design pattern talk by Kaya Weers - 2025 (v2)Design pattern talk by Kaya Weers - 2025 (v2)
Design pattern talk by Kaya Weers - 2025 (v2)
Kaya Weers
 
AI Agents at Work: UiPath, Maestro & the Future of Documents
AI Agents at Work: UiPath, Maestro & the Future of DocumentsAI Agents at Work: UiPath, Maestro & the Future of Documents
AI Agents at Work: UiPath, Maestro & the Future of Documents
UiPathCommunity
 
AsyncAPI v3 : Streamlining Event-Driven API Design
AsyncAPI v3 : Streamlining Event-Driven API DesignAsyncAPI v3 : Streamlining Event-Driven API Design
AsyncAPI v3 : Streamlining Event-Driven API Design
leonid54
 
Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?
Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?
Crazy Incentives and How They Kill Security. How Do You Turn the Wheel?
Christian Folini
 
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
Ivano Malavolta
 
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
Lorenzo Miniero
 
Limecraft Webinar - 2025.3 release, featuring Content Delivery, Graphic Conte...
Limecraft Webinar - 2025.3 release, featuring Content Delivery, Graphic Conte...Limecraft Webinar - 2025.3 release, featuring Content Delivery, Graphic Conte...
Limecraft Webinar - 2025.3 release, featuring Content Delivery, Graphic Conte...
Maarten Verwaest
 
Q1 2025 Dropbox Earnings and Investor Presentation
Q1 2025 Dropbox Earnings and Investor PresentationQ1 2025 Dropbox Earnings and Investor Presentation
Q1 2025 Dropbox Earnings and Investor Presentation
Dropbox
 

C Sharp Jn (5)

  • 1. Software Development Training Program Zeeshan Hanif Zeeshan Hanif
  • 2. DotNet 3.5-101 Lecture 6 Zeeshan Hanif Zeeshan Hanif [email_address] [email_address]
  • 3. Object Oriented Programming Object-oriented programming focuses on the development of self-contained software components, called objects . Objects in Everyday Life Objects are key to understanding object oriented technology. You can look around you now and see many examples of real-world objects: dog, car, television set, bicycle. Zeeshan Hanif
  • 4. Object in Everyday Life All these real world objects have two characteristics: state and behavior . For example car have states (current gear, number of gears, color, number of wheels) and behavior (braking, accelerating, slowing down, changing gears ) etc. Zeeshan Hanif
  • 5. Object in Programming Objects are useful in programming because you can set up a software model of real-world system. Software objects too have state and behavior. A software object maintains its state in one or more variable . A software object implements its behavior with methods . An object is a software bundle of variables and related methods. Zeeshan Hanif
  • 6. Class and Object In the real world, we often have many objects of the same kind For example my car is just one of many cars in the world Using object-oriented terminology, we say that my car object is an instance of the class of objects known as cars. Zeeshan Hanif
  • 7. Class and Object Cars have some state (current gear, one engine, four wheels) and behavior (change gears, brake) in common. However, each car’s state is independent and can be different from that of other cars. A construction company have a blueprint of house but my house is created on the basis of that blueprint. So that blueprint is class and my house is object of that class Zeeshan Hanif
  • 8. Class and Object A software (blueprint or map) for objects is called a class. You can also say that a class is a template After you've created the car class, you can create any number of car objects from the class. Each instance gets its own copy of all the instance variables defined in the class. Zeeshan Hanif
  • 9. Example public class Car { public int wheels; public string color; public int noOfSeats; } Zeeshan Hanif
  • 10. Class Members Instance and Static Fields Instance variables Each object of the class will have its own copy of each of the instance variables that appear in the class definition Static variables A given class will only have one copy of each of its class variable. The class variable exists even if no objects of the class have been created Zeeshan Hanif
  • 11. Zeeshan Hanif Class Definition public class Car{ public static int wheel; public string color; public bool isAutomatic; } Car1 Color isAutomatic Car2 Color isAutomatic Each object gets its own copy Shared between all objects Car.Wheel Car objects wheel
  • 12. Class Members Instance and Static Methods Unlike variables there is not any separate copy for each methods. Therefore, instance and static methods are stored only once, and associated with the class as a whole. Instance variable and methods can not be called from static methods Zeeshan Hanif
  • 13. Class Members Zeeshan Hanif c1 instance Instance Fields color c2 instance Instance Fields color All Methods NoOfWheels() Start() Car Class Static Fields wheel
  • 14. Defining Methods Zeeshan Hanif public int start(int a, string b,......) { // Executable code } The type of the value to be returned Name of the method The specification of the parameters for the method. If the method has no parameters, leave the parentheses empty Access modifier This is called the body of method Method Signature
  • 15. Defining Methods Parameter List Value Parameters Reference Parameters Output Parameters Class Parameters Structure Parameters Argument Value Passing Zeeshan Hanif
  • 16. Encapsulation A powerful benefit of encapsulation is the hiding of implementation details from other objects. This means that the internal portion (variables) of an object has more limited visibility than the external portion (methods). This will protect the internal portion against unwanted external access. Zeeshan Hanif
  • 17. Properties The encapsulation principle leads us to typically store data in private fields and provide access to this data through public accessor methods that allow us to set and get values So we have to create two methods such as GetData() and SetData() C# provides a special property syntax that simplifies this process Zeeshan Hanif
  • 18. Properties syntax Zeeshan Hanif public class Student { private string name; public string GetName () { return name; } public void SetName (string a) { name = a; } } public class Student { private string name; public string Name { get { return name; } set { name = value; } }} Using Property Using Methods
  • 19. Method Overloading If you want to use same method for different type of data processing then you have to overload your method That is two or more method have same names but different signature Zeeshan Hanif
  • 20. Method Overloading Two methods have the same signature if they have the same number of parameters, the parameters have the same data types, and the parameters have the same modifiers (none, ref, out). The return type does not contribute to defining the signature of a method. Zeeshan Hanif
  • 21. Example public class MyMath{ public int FindMax( int a, int b ){ return a>b? a : b; } public string FindMax( string a, string b ){ return a.CompareTo(b) >= 0 ? a : b; } } Zeeshan Hanif
  • 22. this Every instance method has a variable with name this which refers to the current object of which method is being called. It is called implicitly by the compiler when your method refer to any instance variable of the class Zeeshan Hanif
  • 23. Example public class Human { private string name; public Human(string name) { this.name = name; } public void setName(string name){ this.name = name; } } Zeeshan Hanif
  • 24. Constructor The purpose of a constructor is to provide you with the means of initializing the instance variables uniquely for the object that is being created. Constructor is special method with the name of Class and automatically called when an object is created. Zeeshan Hanif
  • 25. Constructor Constructor is special method that is automatically called when an object is created. A Constructor: has no return type Has the same name as the class Usually have public access May take parameters which are passed when invoking new Zeeshan Hanif
  • 26. Constructor public class Human { private string name; private string address; private int age; public Human(string a, string b, int c) { name = a; address = b; age = c; } } Zeeshan Hanif
  • 27. Multiple Constructor Default constructor More then one Constructor just like method overloading Duplicating objects using constructor Calling constructor from constructor(eg. This) Static constructor Zeeshan Hanif
  • 28. Constant and Readonly Fields const If a field is declared as const then it is not really a variable at all. It is treated as a fixed hard coded value in the program. const variable is implicitly static and its value can not be changed Zeeshan Hanif
  • 29. const public class Car { public const int wheel = 4; public void ChangeWheel(){ wheel= 5; // compile-time error } } Zeeshan Hanif
  • 30. readonly readonly keyword gives a bit more flexibility than const, allowing for the case in which you might want a field be to constant, but need to carry out some calculations to determine its initial value. readonly can be static or non-static but once readonly variable is initialize it can not be changed Zeeshan Hanif
  • 31. readonly public class RegistrationForm { public readonly DateTime time; public RegistrationForm() { // one time initialization time = DateTime.Now; // now this can not be changed } } Zeeshan Hanif
  • 32. Variable length parameter Lists When you to pass undefined number of parameters to any method then you use params keyword You can pass any number of parameter and it treats it as array. WriteLine method is an example Zeeshan Hanif
  • 33. params public int FindMax( params int[] a ){ int max = 0; for(int i=0;i< a.Lenght ;i++){ if(a[i] > max) max = a[i]; } return max; } Calling this method like this FindMax( 4,5,6,7,5,3,2,3,3,4,3 ); Zeeshan Hanif
  翻译: