Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

Variables - Doing arithmetic operations in C#

This example illustrates the simple arithmetic operations over variables.
Assignment is done here from right to left.

Syntax:
  1. <actual variable holder> = <operational expression>

  1. Example: i=i+10;
  2. i - actual holder
  3. i+10 - operational expression


  1. using System;
  2.  
  3. namespace forgetCode
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. //Simple arithmetic
  10. int i = 10;
  11. Console.WriteLine(i * i);
  12.  
  13. // New value assigned to same variable (Right to left assignment)
  14. int j = 20;
  15. j = j + 10;
  16. Console.WriteLine(j);
  17.  
  18. int k = 100;
  19. k = k % 10;
  20. Console.WriteLine(k);
  21.  
  22. }
  23. }
  24. }


Output:
  1. 100
  2. 30
  3. 0


..