Tutorial Gateway

  • C
  • C#
  • Python
  • SQL
  • Java
  • JS
  • BI Tools
    • Informatica
    • Talend
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • R Tutorial
    • Alteryx
    • QlikView
  • More
    • C Programs
    • C++ Programs
    • Go Programs
    • Python Programs
    • Java Programs
  • MySQL

C# Assignment Operators

The C# Assignment operators are associated with arithmetic operators as a prefix, i.e., +=, -=, *=, /=, %=. The following tables show the available list of assignment operators.

C # Assignment OperatorsOperationExample
+=Plus Equal Tox+=15 is x=x+15
-=Minus Equal Tox- =15 is x=x-15
*=Multiply Equal Tox*=16 is x=x+16
%=Modulus Equal Tox%=15 is x=x%15
/=Divide Equal Tox/=16 is x=x/16

C# Assignment Operators Example

Let us see an example code using the C # assignment operators.

using System;
 
class Assignment_Operators
{
     static void Main()
     {
         int x = 15;

         x += 5;
         Console.WriteLine("x += 5 results x = " + x);
 
         x -= 10;
         Console.WriteLine("x -= 10 results x = " + x);
 
         x *= 2;
         Console.WriteLine("x *= 2 results x = " + x);
 
         x /= 3;
         Console.WriteLine("x /= 3 results x = " + x);
 
         x %= 4;
         Console.WriteLine("x %= 4 results x = " + x);
     }
}

OUTPUT

C# Assignment Operators 1

x is an integer on which we have applied assignment operators in the above C# code.

x+=5
x = x+5 = 20;

x-=10
x = x-10 = 20-10 = 10

x*=2
x = x * 2 = 10 * 2 = 20

x/=3
x = x / 3 = 20 / 3 = 6

x%=4
x = x % 4 = 6 % 4 = 2

Filed Under: C#

  • Dot Net Framework
  • C# Basic Example Program
  • C# Variables
  • C# Constant
  • C# Keywords
  • C# Regular Expressions
  • C# Built in Data Types
  • C# Nullable Types
  • C# Data type Conversion
  • C# Date and Time Format
  • C# Enum or Enumerator
  • C# Value and Reference types
  • C# Operators
  • C# Arithmetic Operators
  • C# Assignment Operators
  • C# Bitwise Operators
  • C# Logical Operators
  • C# Null Coalescing operator
  • C# Relational Operators
  • C# Ternary Operator
  • C# Unary Operators
  • C# If Statement
  • C# If Else Statement
  • C# Else if Statement
  • C# Nested If Statement
  • C# Break Statement
  • C# Continue Statement
  • C# goto statement
  • C# Switch Case
  • C# While Loop
  • C# Do while loop
  • C# For Loop
  • C# Foreach loop
  • C# String Builder
  • C# String
  • C# String Functions
  • C# Array
  • C# Array Functions
  • C# Multi Dimensional Arrays
  • C# Jagged Array
  • C# OOPS Introduction
  • C# Constructor
  • C# Destructor
  • C# Access Modifiers
  • C# Inheritance

Copyright © 2021ยท All Rights Reserved by Suresh.
About | Contact | Privacy Policy