SlideShare a Scribd company logo
Learn C# Programming
Polymorphism & Operator Overloading
Eng Teong Cheah
MVP Visual Studio & Development Technologies
Polymorphism
Polymorphism
The word polymorphism means having many forms. In object-oriented programming
paradigm, polymorphism is often expressed as ‘one interface, multiple functions’.
Polymorphism can be static or dynamic.
In static polymorphism, the response to a function is determined at the compile time.
In dynamic polymorphism, it is decided at runtime.
Static Polymorphism
The mechanism of linking a function with an object during compile time is called early
binding. It is also called static binding.
C# provides two techniques to implement static polymorphism.
They are:
- Function overloading
- Operator overloading
Function Overloading
You can have multiple definitions for the same function name in the same scope.
The definition of the function must differ from each other by the types and/or the
number of arguments in the argument list.
You cannot overload function declarations that differ only by return type.
Demo – Function
Overloading
Dynamic Polymorphism
C# allows you to create abstract classes that are used to provide partial class
implementation of an interface. Implementation is completed when a derived class
inherits from it.
Abstract classes contain abstract methods, which is implemented by the derived class.
The derived classes have more specialized functionality.
Dynamic Polymorphism
Here are the rules about abstract classes-
- You cannot create an instance of an abstract class
- You cannot declare an abstract method outside an abstract class
- When a class is declared sealed. It cannot be inherited, abstract classes cannot be
declared sealed.
Demo – Dynamic
Polymorphism
Dynamic Polymorphism
When you have a function defined in a class that you want to be implemented in an
inherited class(es), you use virtual functions.
The virtual functions could be implemented differently in different inherited class and
the call to these functions will be decided at runtime.
Dynamic polymorphism is implemented by abstract classes and virtual functions.
Demo 2 – Dynamic
Polymorphism
Operator Overloading
Operator Overloading
You can redefine or overload most of the built-in operators available in C#.
Thus programmer can use operators with user defined types as well.
Overloaded operators followed by the symbol for the operator being defined.
Similar to any other function, an overload operator has a return type and parameter list.
Operator Overloading
For example, go through the following function –
The above function implements the addition (+) for a user defined class Box.
It adds the attributes of two Box objects and returns the resultant Box object.
Demo – Implementing
the Operator
Overloading
Overloadable and Non-Overloadable
Operators
The following table describes the overload ability of the operators in C#
Demo – Overloadable &
Non-Overloadable
Operators
Related Content
TutorialsPoint
www.tutorialspoint.com
Thank you

More Related Content

What's hot (19)

PPTX
Pointers,virtual functions and polymorphism cpp
rajshreemuthiah
 
PPTX
07. Virtual Functions
Haresh Jaiswal
 
PPT
3 Function Overloading
Praveen M Jigajinni
 
PPT
16 virtual function
Docent Education
 
PPTX
Polymorphism Using C++
PRINCE KUMAR
 
PPTX
Pointers, virtual function and polymorphism
lalithambiga kamaraj
 
ODP
Ppt of c vs c#
shubhra chauhan
 
PPT
pointers, virtual functions and polymorphisms in c++ || in cpp
gourav kottawar
 
PDF
C++ Training
SubhendraBasu5
 
PDF
Functions in C++
Pranali Chaudhari
 
PPTX
Function overloading
Selvin Josy Bai Somu
 
PPTX
C++ vs C#
sudipv
 
PPTX
Presentation on overloading
Charndeep Sekhon
 
PPSX
C++ Programming Language
Mohamed Loey
 
PPTX
Polymorphism in c++(ppt)
Sanjit Shaw
 
ODP
Ppt of c++ vs c#
shubhra chauhan
 
DOCX
Virtual function
harman kaur
 
PPTX
Function overloading in c++
Learn By Watch
 
PPTX
Polymorphism in C++
Rabin BK
 
Pointers,virtual functions and polymorphism cpp
rajshreemuthiah
 
07. Virtual Functions
Haresh Jaiswal
 
3 Function Overloading
Praveen M Jigajinni
 
16 virtual function
Docent Education
 
Polymorphism Using C++
PRINCE KUMAR
 
Pointers, virtual function and polymorphism
lalithambiga kamaraj
 
Ppt of c vs c#
shubhra chauhan
 
pointers, virtual functions and polymorphisms in c++ || in cpp
gourav kottawar
 
C++ Training
SubhendraBasu5
 
Functions in C++
Pranali Chaudhari
 
Function overloading
Selvin Josy Bai Somu
 
C++ vs C#
sudipv
 
Presentation on overloading
Charndeep Sekhon
 
C++ Programming Language
Mohamed Loey
 
Polymorphism in c++(ppt)
Sanjit Shaw
 
Ppt of c++ vs c#
shubhra chauhan
 
Virtual function
harman kaur
 
Function overloading in c++
Learn By Watch
 
Polymorphism in C++
Rabin BK
 

Similar to Learn C# Programming Polymorphism & Operator Overloading (20)

PPT
An Introduction to C# and .NET Framework (Basic)
Khubaib Ahmad Kunjahi
 
PPTX
28csharp
Sireesh K
 
PPTX
28c
Sireesh K
 
PPT
Opps
Lalit Kale
 
PPTX
Polymorphism
Arif Ansari
 
PPTX
Polymorphism in C# Function overloading in C#
Abid Kohistani
 
PDF
Btech chapter notes batcha ros zir skznzjsbaajz z
bhatiaanushka101
 
PDF
Polymorphism, Abstarct Class and Interface in C#
Umar Farooq
 
PDF
Xamarin: Inheritance and Polymorphism
Eng Teong Cheah
 
PPTX
C# interview
Thomson Reuters
 
PPTX
Whats New In C# 4 0 - NetPonto
Paulo Morgado
 
PPT
Classes2
phanleson
 
PPTX
OOPS – General Understanding in .NET
Sabith Byari
 
PPTX
Object oriented programming
Nadeesha Thilakarathne
 
PDF
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
Akhil Mittal
 
PDF
Polymorphism in Java by Animesh Sarkar
Animesh Sarkar
 
PDF
vdocument in_polymorphism-in-cppt_python.pdf
parveen204931475
 
PPTX
Polymorphism OOP new Gate.pptx
AssadLeo1
 
An Introduction to C# and .NET Framework (Basic)
Khubaib Ahmad Kunjahi
 
28csharp
Sireesh K
 
Polymorphism
Arif Ansari
 
Polymorphism in C# Function overloading in C#
Abid Kohistani
 
Btech chapter notes batcha ros zir skznzjsbaajz z
bhatiaanushka101
 
Polymorphism, Abstarct Class and Interface in C#
Umar Farooq
 
Xamarin: Inheritance and Polymorphism
Eng Teong Cheah
 
C# interview
Thomson Reuters
 
Whats New In C# 4 0 - NetPonto
Paulo Morgado
 
Classes2
phanleson
 
OOPS – General Understanding in .NET
Sabith Byari
 
Object oriented programming
Nadeesha Thilakarathne
 
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
Akhil Mittal
 
Polymorphism in Java by Animesh Sarkar
Animesh Sarkar
 
vdocument in_polymorphism-in-cppt_python.pdf
parveen204931475
 
Polymorphism OOP new Gate.pptx
AssadLeo1
 
Ad

More from Eng Teong Cheah (20)

PDF
Modern Cross-Platform Apps with .NET MAUI
Eng Teong Cheah
 
PDF
Efficiently Removing Duplicates from a Sorted Array
Eng Teong Cheah
 
PDF
Monitoring Models
Eng Teong Cheah
 
PDF
Responsible Machine Learning
Eng Teong Cheah
 
PDF
Training Optimal Models
Eng Teong Cheah
 
PDF
Deploying Models
Eng Teong Cheah
 
PDF
Machine Learning Workflows
Eng Teong Cheah
 
PDF
Working with Compute
Eng Teong Cheah
 
PDF
Working with Data
Eng Teong Cheah
 
PDF
Experiments & TrainingModels
Eng Teong Cheah
 
PDF
Automated Machine Learning
Eng Teong Cheah
 
PDF
Getting Started with Azure Machine Learning
Eng Teong Cheah
 
PDF
Hacking Containers - Container Storage
Eng Teong Cheah
 
PDF
Hacking Containers - Looking at Cgroups
Eng Teong Cheah
 
PDF
Hacking Containers - Linux Containers
Eng Teong Cheah
 
PDF
Data Security - Storage Security
Eng Teong Cheah
 
PDF
Application Security- App security
Eng Teong Cheah
 
PDF
Application Security - Key Vault
Eng Teong Cheah
 
PDF
Compute Security - Container Security
Eng Teong Cheah
 
PDF
Compute Security - Host Security
Eng Teong Cheah
 
Modern Cross-Platform Apps with .NET MAUI
Eng Teong Cheah
 
Efficiently Removing Duplicates from a Sorted Array
Eng Teong Cheah
 
Monitoring Models
Eng Teong Cheah
 
Responsible Machine Learning
Eng Teong Cheah
 
Training Optimal Models
Eng Teong Cheah
 
Deploying Models
Eng Teong Cheah
 
Machine Learning Workflows
Eng Teong Cheah
 
Working with Compute
Eng Teong Cheah
 
Working with Data
Eng Teong Cheah
 
Experiments & TrainingModels
Eng Teong Cheah
 
Automated Machine Learning
Eng Teong Cheah
 
Getting Started with Azure Machine Learning
Eng Teong Cheah
 
Hacking Containers - Container Storage
Eng Teong Cheah
 
Hacking Containers - Looking at Cgroups
Eng Teong Cheah
 
Hacking Containers - Linux Containers
Eng Teong Cheah
 
Data Security - Storage Security
Eng Teong Cheah
 
Application Security- App security
Eng Teong Cheah
 
Application Security - Key Vault
Eng Teong Cheah
 
Compute Security - Container Security
Eng Teong Cheah
 
Compute Security - Host Security
Eng Teong Cheah
 
Ad

Recently uploaded (20)

PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 

Learn C# Programming Polymorphism & Operator Overloading

  • 1. Learn C# Programming Polymorphism & Operator Overloading Eng Teong Cheah MVP Visual Studio & Development Technologies
  • 3. Polymorphism The word polymorphism means having many forms. In object-oriented programming paradigm, polymorphism is often expressed as ‘one interface, multiple functions’. Polymorphism can be static or dynamic. In static polymorphism, the response to a function is determined at the compile time. In dynamic polymorphism, it is decided at runtime.
  • 4. Static Polymorphism The mechanism of linking a function with an object during compile time is called early binding. It is also called static binding. C# provides two techniques to implement static polymorphism. They are: - Function overloading - Operator overloading
  • 5. Function Overloading You can have multiple definitions for the same function name in the same scope. The definition of the function must differ from each other by the types and/or the number of arguments in the argument list. You cannot overload function declarations that differ only by return type.
  • 7. Dynamic Polymorphism C# allows you to create abstract classes that are used to provide partial class implementation of an interface. Implementation is completed when a derived class inherits from it. Abstract classes contain abstract methods, which is implemented by the derived class. The derived classes have more specialized functionality.
  • 8. Dynamic Polymorphism Here are the rules about abstract classes- - You cannot create an instance of an abstract class - You cannot declare an abstract method outside an abstract class - When a class is declared sealed. It cannot be inherited, abstract classes cannot be declared sealed.
  • 10. Dynamic Polymorphism When you have a function defined in a class that you want to be implemented in an inherited class(es), you use virtual functions. The virtual functions could be implemented differently in different inherited class and the call to these functions will be decided at runtime. Dynamic polymorphism is implemented by abstract classes and virtual functions.
  • 11. Demo 2 – Dynamic Polymorphism
  • 13. Operator Overloading You can redefine or overload most of the built-in operators available in C#. Thus programmer can use operators with user defined types as well. Overloaded operators followed by the symbol for the operator being defined. Similar to any other function, an overload operator has a return type and parameter list.
  • 14. Operator Overloading For example, go through the following function – The above function implements the addition (+) for a user defined class Box. It adds the attributes of two Box objects and returns the resultant Box object.
  • 15. Demo – Implementing the Operator Overloading
  • 16. Overloadable and Non-Overloadable Operators The following table describes the overload ability of the operators in C#
  • 17. Demo – Overloadable & Non-Overloadable Operators