C# Program to Overload Unary Increment (++) and Decrement (--) Operators Last Updated : 16 Nov, 2021 Comments Improve Suggest changes Like Article Like Report In C#, overloading is the common way of implementing polymorphism. It is the ability to redefine a function in more than one form. A user can implement method overloading by defining two or more methods in a class sharing the same name but with different method signatures. So in this article, we will learn how to overload unary increment and decrement operators. Overloading Decrement OperatorIn C#, the decrement operator(--) is used to decrement an integer value by one. It is of two types pre-decrement operator and post decrement operator. When this operator is placed before any variable name then such type of operator is known as pre-decrement operator, e.g., --y whereas when the operator is placed after any variable name then such type of operator is known as post-decrement operator, e.g., y--. We can also overload the decrement operator using the following syntax. Here we will pass the object as the parameter and then set the decrement value to object value and this method will return the decremented value. Syntax: public static GFG operator --(GFG obj) { obj.value = --obj.value; return obj; } Example: Input : 50 Output : 49 Input : 79 Output : 78 Example: C# // C# program to demonstrate overloading decrement operator using System; class GFG{ // Declare integer variable private int value; // Initialize data members public GFG(int value){this.value = value;} // Overload unary decrement operator public static GFG operator--(GFG obj) { obj.value = --obj.value; return obj; } // Display method to display the value public void Display() { Console.WriteLine("Values : " + value); Console.WriteLine(); } } class Geeks{ // Driver code static void Main(string[] args) { // Declare the object and assign // the value to 50 GFG obj = new GFG(50); // Call the unary decrement overload method obj--; // Call the display method obj.Display(); } } Output: Values : 49Overload Increment OperatorIn C#, the increment operator(++) is used to increment an integer value by one. It is of two types pre-increment operator and post-increment operator. When this operator is placed before any variable name then such type of operator is known as pre-increment operator, e.g., ++y whereas when the operator is placed after any variable name then such type of operator is known as post-increment operator, e.g., y++. We can also overload the increment operator using the following syntax. Here we will pass the object as the parameter and then set the increment value to object value and this method will return the incremented value. Syntax: public static GFG operator ++(GFG obj) { obj.value = ++obj.value; return obj; } Example: Input : 50 Output : 51 Input : 79 Output : 80 Example: C# // C# program to demonstrate overloading // increment operator using System; class GFG{ // Declare integer variable private int value; // Initialize data members public GFG(int value) { this.value = value; } // Overload unary increment operator public static GFG operator ++(GFG obj) { obj.value = ++obj.value; return obj; } // Display method to display the value public void Display() { Console.WriteLine("Values : " + value); Console.WriteLine(); } } class Geeks{ // Driver code static void Main(string[] args) { // Declare the object and assign the value to 50 GFG obj = new GFG(50); // Call the unary increment overload method obj++; // Call the display method obj.Display(); } } Output: Values : 51 Comment More infoAdvertise with us Next Article C# Program to Overload Unary Increment (++) and Decrement (--) Operators M manojkumarreddymallidi Follow Improve Article Tags : C# CSharp Operators CSharp-programs Similar Reads Increment and Decrement Operators in Programming Increment and Decrement Operators are Unary Operators commonly used in programming to increase or decrease the value of a variable by one, respectively. They provide a shorthand way to perform these common operations. Table of Content Increment OperatorsIncrement Operators in CIncrement Operators in 7 min read Pre Increment and Post Increment Operator in Programming Pre Increment Operator and Post Increment Operator are the two ways of using the Increment operator to increment the value of a variable by 1. They can be used with numeric data values such as int, float, double, etc. Pre-increment and Post-increment perform similar tasks with minor distinctions. In 6 min read C++ Increment and Decrement Operators Prerequisite: Operators in C++ What is a C++ increment Operator? The C++ increment operator is a unary operator. The symbol used to represent the increment operator is (++). The increment operator increases the value stored by the variable by 1. This operator is used for Numeric values only. There a 4 min read Pre and Post Decrement Operator in Programming Pre-decrement and post-decrement are the two ways of using the decrement operator to decrement the value of a variable by 1. They can be used with numeric data type values such as int, float, double, etc. Pre-decrement and Post-decrement perform similar tasks with minor distinctions. Table of Conten 5 min read Operator Overloading in Programming Operator Overloading is a feature in some programming languages used to redefine or "overload" the standard behavior of operators (such as +, -, *, etc.) to work with user-defined data types. This is useful when working with objects of custom classes. In this article, we will learn about the basics 4 min read Difference between Unary and Binary Operators Unary Operators and Binary operators are both fundamental concepts in computer science and programming languages, especially in the context of arithmetic and logical operations. Here's a breakdown of the differences between them: Unary Operators:Unary Operator is an operator that operates on a singl 2 min read Unary Operators in Programming In programming, operators act as powerful tools for manipulating data and performing various operations. Among these, unary operators stand out, functioning on a single operand to transform or evaluate data in different ways. This post explains the types, implementations, and best practices associat 9 min read What are Operators in Programming? Operators in programming are essential symbols that perform operations on variables and values, enabling tasks like arithmetic calculations, logical comparisons, and bitwise manipulations. In this article, we will learn about the basics of operators and their types. Operators in Programming Table of 15+ min read Arithmetic Operators in Solidity Arithmetic operators are used to perform arithmetic or mathematical operations. Solidity has the following types of arithmetic operators: Addition: The addition operator takes two operands and results in a sum of these operands. It is denoted by +.Subtraction: The subtraction operator takes two oper 2 min read Difference between Operator Precedence and Operator Associativity In programming, operators are used to perform various operations on data. Understanding how operators interact with each other is crucial for writing correct and efficient code. In this article, we will explore the two most important concepts which are Operator Precedence and Operator Associativity. 3 min read Like