Advertisement
Guest User

Untitled

a guest
Aug 24th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. using System;
  2.  
  3. namespace operators
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. int myVariable;
  10.  
  11. //Assignment operator.
  12. int a = 5;
  13. int b = 2;
  14.  
  15. //Arithemntic operators//////////////////////////////////////
  16.  
  17. //Addition operator.
  18. myVariable = a + b;
  19. Console.WriteLine(myVariable);
  20.  
  21. //Subtraction operator.
  22. myVariable = a - b;
  23. Console.WriteLine(myVariable);
  24.  
  25. //Multiplication operator.
  26. myVariable = a * b;
  27. Console.WriteLine(myVariable);
  28.  
  29. //Division operator.
  30. myVariable = a / b;
  31. Console.WriteLine(myVariable);
  32.  
  33. //Increment by one operator.
  34. myVariable = a++ ;
  35. Console.WriteLine(myVariable);
  36.  
  37. //Decrement by one operator.
  38. myVariable = b--;
  39. Console.WriteLine(myVariable);
  40.  
  41. //Addition
  42. myVariable = 10;
  43.  
  44. myVariable = myVariable + a;
  45. //The code above is the same the code below:
  46. myVariable += a;
  47.  
  48. Console.WriteLine(myVariable);
  49.  
  50. //////////////////////////////////////////////////////////
  51.  
  52.  
  53.  
  54. //Comparison Operators////////////////////////////////////
  55.  
  56. // == : equals to
  57. //!= : doesn't equal
  58. //< > : bigger/smaller than
  59. //<= >= : bigger or equal/smaller or equal than
  60. //!myBoolVariable : not
  61.  
  62. //An example of how to use a comparison operator.
  63. a = 10;
  64. b = 5;
  65.  
  66. if (a > b)
  67. {
  68. Console.WriteLine("a is bigger than b");
  69. }
  70. else
  71. {
  72. Console.WriteLine("b is bigger than a.");
  73. }
  74.  
  75.  
  76. //////////////////////////////////////////////////////////
  77.  
  78.  
  79.  
  80. //Logical Operators///////////////////////////////////////
  81.  
  82. //&& : and
  83. //|| : or
  84.  
  85. //An example of how to use a logical operator.
  86. a = 10;
  87. b = 5;
  88. bool myBool = true;
  89.  
  90. if ((a > b) && myBool) //Just like in math the expression in the () will be evaluated first.
  91. {
  92. Console.WriteLine("a is bigger than b AND myBool is true.");
  93. }
  94.  
  95.  
  96. //////////////////////////////////////////////////////////
  97.  
  98. Console.ReadLine();
  99. }
  100. }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement