C# Assignment Operators

assignment_icon
In this chapter you will learn:

  • What is C# Assignment Operators?
  • How many types of assignment operators in C sharp?
  • How to use assignment operator in program?

The C# assignment operator is generally suffix with arithmetic operators. The symbol of c sharp assignment operator is “=” without quotes. The assignment operator widely used with C# programming. Consider a simple example:

result=num1+num2;

In this example, the equal to (=) assignment operator assigns the value of num1 + num2 into result variable.

Various types of C# assignment operators are mentioned below:

Assignment Operators:

Assignment OperatorsUsageExamples
= (Equal to)result=5Assign the value 5 for result
+= (Plus Equal to)result+=5Same as result=result+5
-= (Minus Equal to)result-=5Same as result=result-5
*= (Multiply Equal to)result*=5Same as result=result*5
/= (Divide Equal to)result/=5Same as result=result/5
%= (Modulus Equal to)result%=5Same as result=result%5

Output

Add = 15

Subtraction = 10

Multiplication = 50

Modulus = 0
__

Summary

In this chapter, you learned about different types of assignment operators in C#. You also learned how to use these assignment operators in a program. In next chapter, you will learn about Unary Operator in C#.


2 thoughts on “C# Assignment Operators”

  1. num1 -= num2; // same as num1=num1-num2
    Console.WriteLine(“\n\nSubtraction = {0}”, num1);

    it is giving output as 10, but as per logic defined it should be 5.

    num1 =10
    num2 = 5
    num1 -= num2; // same as num1=num1-num2 taht means num1= 10-5
    it is 5 but it giving 10

Leave a Reply

Your email address will not be published. Required fields are marked *