23 November 2019 N.Nandhini AP/MCA 1
Operator overloading
 What is Overloading?
 Types of Overloading.
 Operator Overloading.
 Types of Operator Overloading.
23 November 2019 N.Nandhini AP/MCA 2
What is Overloading?
Two Type is
1. Method Overloading
2. Operator Overloading
23 November 2019 N.Nandhini AP/MCA 3
Overloading
23 November 2019 N.Nandhini AP/MCA 4
Cont..
Rules for Operator Overloading
 Only Predefined Operator is Overloaded.
 Cannot Change Operator Template.
 Natural meaning and overloaded meaning is same.
 Must have a user defined operand.
Types of Operator Overloading.
 Unary Operator Overloading.
 Binary Operator Overloading.
Syntax
modifiers type operator op(arglist)
{
Method body//task defined
}
23 November 2019 N.Nandhini AP/MCA 5
Overloadable Operator Not Overloadable Operator
Category Operators Category Operators
BinaryArithmetic + * / - % Conditional && ||
UnaryArithmetic + - ++ -- Operators += -= *=
Binary Bitwise & | ^ << >> Compound /= %=
Unary Bitwise ! ~ true false assignment [] () ?:
Logical Operators == != >= < <== new
> Other operators sizeof
23 November 2019 N.Nandhini AP/MCA 6
Unary Operator Overloading
23 November 2019 N.Nandhini AP/MCA 7
Binary Operator Overloading
Binary Operators will work with two Operands. Examples of binary operators
include the Arithmetic Operators (+, -, *, /, %), Arithmetic Assignment operators
(+=, -+, *=, /+, %=) and Relational Operators etc. Overloading a binary operator
is similar to overloading a unary operator, except that a binary operator requires
an additional parameter.
23 November 2019 N.Nandhini AP/MCA 8
Benefits of Operator Overloading :
1. Operator Overloading provides additional capabilities to
C# operators when they are applied to user-defined data
types.
2. Operators may be considered as functions internal to the
compiler.
23 November 2019 N.Nandhini AP/MCA 9
23 November 2019 N.Nandhini AP/MCA 10
23 November 2019 N.Nandhini AP/MCA 11

Operator overloading

  • 1.
    23 November 2019N.Nandhini AP/MCA 1 Operator overloading  What is Overloading?  Types of Overloading.  Operator Overloading.  Types of Operator Overloading.
  • 2.
    23 November 2019N.Nandhini AP/MCA 2 What is Overloading? Two Type is 1. Method Overloading 2. Operator Overloading
  • 3.
    23 November 2019N.Nandhini AP/MCA 3 Overloading
  • 4.
    23 November 2019N.Nandhini AP/MCA 4 Cont.. Rules for Operator Overloading  Only Predefined Operator is Overloaded.  Cannot Change Operator Template.  Natural meaning and overloaded meaning is same.  Must have a user defined operand. Types of Operator Overloading.  Unary Operator Overloading.  Binary Operator Overloading. Syntax modifiers type operator op(arglist) { Method body//task defined }
  • 5.
    23 November 2019N.Nandhini AP/MCA 5 Overloadable Operator Not Overloadable Operator Category Operators Category Operators BinaryArithmetic + * / - % Conditional && || UnaryArithmetic + - ++ -- Operators += -= *= Binary Bitwise & | ^ << >> Compound /= %= Unary Bitwise ! ~ true false assignment [] () ?: Logical Operators == != >= < <== new > Other operators sizeof
  • 6.
    23 November 2019N.Nandhini AP/MCA 6 Unary Operator Overloading
  • 7.
    23 November 2019N.Nandhini AP/MCA 7 Binary Operator Overloading Binary Operators will work with two Operands. Examples of binary operators include the Arithmetic Operators (+, -, *, /, %), Arithmetic Assignment operators (+=, -+, *=, /+, %=) and Relational Operators etc. Overloading a binary operator is similar to overloading a unary operator, except that a binary operator requires an additional parameter.
  • 8.
    23 November 2019N.Nandhini AP/MCA 8 Benefits of Operator Overloading : 1. Operator Overloading provides additional capabilities to C# operators when they are applied to user-defined data types. 2. Operators may be considered as functions internal to the compiler.
  • 9.
    23 November 2019N.Nandhini AP/MCA 9
  • 10.
    23 November 2019N.Nandhini AP/MCA 10
  • 11.
    23 November 2019N.Nandhini AP/MCA 11