
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
Difference between prefix and postfix operators in C#?
Prefix Operator
The increment operator ++ if used as prefix on a variable, the value of variable gets incremented by 1. After that the value is returned unlike Postfix operator. It is called Prefix increment operator. In the same way the prefix decrement operator works but it decrements by 1.
For example, an example of prefix operator −
++a;
The following is an example demonstrating Prefix increment operator −
Example
using System; class Program { static void Main() { int a, b; a = 50; Console.WriteLine(++a); b = a; Console.WriteLine(a); Console.WriteLine(b); } }
output
51 51 51
Postfix Operator
The increment operator ++ if used as postfix on a variable, the value of variable is first returned and then gets incremented by 1. It is called Postfix increment operator. In the same way the decrement operator works but it decrements by 1.
An example of Postfix operator.
a++;
The following is an example showing how to work with postfix operator −
Example
using System; class Program { static void Main() { int a, b; a = 10; Console.WriteLine(a++); b = a; Console.WriteLine(a); Console.WriteLine(b); } }
Output
10 11 11
- Related Articles
- What is the difference between prefix and postfix operators in C++?
- Prefix and Postfix Expressions in Data Structure
- Differentiate between the prefix and postfix forms of the ++ operator in java?
- Precedence of postfix ++ and prefix ++ in C/C++
- Prefix to Postfix Conversion in C++
- What are postfix operators in C++?
- What are postfix operators in C#?
- Equality checks in Kotlin (Difference between "==" and "===" Operators)
- What is the difference between | and || operators in c#?
- What is the difference between >> and >>> operators in Java?
- What is the difference between = and == operators in Python?
- What is the difference between = and: = assignment operators?
- What is the difference between the != and operators in Python?
- What is the difference between the | and || or operators in C#?
- Write the main difference between '==' and '===' operators in javascript?

Advertisements