In: Computer Science
Explain how to use the C# shortcut arithmetic operators -=, *=, and /=.
using System;
namespace Demo {
class MyApplication {
static void Main(string[] args) {
int a = 5;
a += 9;
Console.WriteLine(a); // output: 14
a -= 4;
Console.WriteLine(a); // output: 10
a *= 2;
Console.WriteLine(a); // output: 20
a /= 4;
Console.WriteLine(a); // output: 5
a %= 3;
Console.WriteLine(a); // output: 2
}
}
}
x op= y equivalent x = x op y ( op +,-,*,/ )
x+=y equivalent x=x+y
x-=y equivalent x=x-y
x*=y equivalent x=x*y
x/=y equivalent x=x/y