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

PPTX
Polymorphism
PPTX
Compile time polymorphism
PPTX
Polymorphism
PPTX
C++ concept of Polymorphism
PPT
C++ polymorphism
PPTX
Function overloading and overriding
PPTX
Polymorphismupload
PDF
Operator overloading
Polymorphism
Compile time polymorphism
Polymorphism
C++ concept of Polymorphism
C++ polymorphism
Function overloading and overriding
Polymorphismupload
Operator overloading

What's hot (19)

PPTX
Pointers,virtual functions and polymorphism cpp
PPTX
07. Virtual Functions
PPT
3 Function Overloading
PPT
16 virtual function
PPTX
Polymorphism Using C++
PPTX
Pointers, virtual function and polymorphism
ODP
Ppt of c vs c#
PPT
pointers, virtual functions and polymorphisms in c++ || in cpp
PDF
C++ Training
PDF
Functions in C++
PPTX
Function overloading
PPTX
C++ vs C#
PPTX
Presentation on overloading
PPSX
C++ Programming Language
PPTX
Polymorphism in c++(ppt)
ODP
Ppt of c++ vs c#
DOCX
Virtual function
PPTX
Function overloading in c++
PPTX
Polymorphism in C++
Pointers,virtual functions and polymorphism cpp
07. Virtual Functions
3 Function Overloading
16 virtual function
Polymorphism Using C++
Pointers, virtual function and polymorphism
Ppt of c vs c#
pointers, virtual functions and polymorphisms in c++ || in cpp
C++ Training
Functions in C++
Function overloading
C++ vs C#
Presentation on overloading
C++ Programming Language
Polymorphism in c++(ppt)
Ppt of c++ vs c#
Virtual function
Function overloading in c++
Polymorphism in C++
Ad

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

PPT
An Introduction to C# and .NET Framework (Basic)
PPTX
PPTX
28csharp
PPT
PPTX
Polymorphism
PPTX
Polymorphism in C# Function overloading in C#
PDF
Btech chapter notes batcha ros zir skznzjsbaajz z
PDF
Polymorphism, Abstarct Class and Interface in C#
PDF
Xamarin: Inheritance and Polymorphism
PPTX
C# interview
PPTX
Whats New In C# 4 0 - NetPonto
PPT
Classes2
PPTX
OOPS – General Understanding in .NET
PPTX
Object oriented programming
PDF
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
PDF
Polymorphism in Java by Animesh Sarkar
PDF
vdocument in_polymorphism-in-cppt_python.pdf
PPTX
Polymorphism OOP new Gate.pptx
An Introduction to C# and .NET Framework (Basic)
28csharp
Polymorphism
Polymorphism in C# Function overloading in C#
Btech chapter notes batcha ros zir skznzjsbaajz z
Polymorphism, Abstarct Class and Interface in C#
Xamarin: Inheritance and Polymorphism
C# interview
Whats New In C# 4 0 - NetPonto
Classes2
OOPS – General Understanding in .NET
Object oriented programming
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
Polymorphism in Java by Animesh Sarkar
vdocument in_polymorphism-in-cppt_python.pdf
Polymorphism OOP new Gate.pptx
Ad

More from Eng Teong Cheah (20)

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

Recently uploaded (20)

PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Empathic Computing: Creating Shared Understanding
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
MYSQL Presentation for SQL database connectivity
PDF
cuic standard and advanced reporting.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Reach Out and Touch Someone: Haptics and Empathic Computing
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Chapter 3 Spatial Domain Image Processing.pdf
Encapsulation_ Review paper, used for researhc scholars
The AUB Centre for AI in Media Proposal.docx
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
“AI and Expert System Decision Support & Business Intelligence Systems”
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Digital-Transformation-Roadmap-for-Companies.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Empathic Computing: Creating Shared Understanding
Unlocking AI with Model Context Protocol (MCP)
MYSQL Presentation for SQL database connectivity
cuic standard and advanced reporting.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...

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