Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace operators
- {
- class Program
- {
- static void Main(string[] args)
- {
- int myVariable;
- //Assignment operator.
- int a = 5;
- int b = 2;
- //Arithemntic operators//////////////////////////////////////
- //Addition operator.
- myVariable = a + b;
- Console.WriteLine(myVariable);
- //Subtraction operator.
- myVariable = a - b;
- Console.WriteLine(myVariable);
- //Multiplication operator.
- myVariable = a * b;
- Console.WriteLine(myVariable);
- //Division operator.
- myVariable = a / b;
- Console.WriteLine(myVariable);
- //Increment by one operator.
- myVariable = a++ ;
- Console.WriteLine(myVariable);
- //Decrement by one operator.
- myVariable = b--;
- Console.WriteLine(myVariable);
- //Addition
- myVariable = 10;
- myVariable = myVariable + a;
- //The code above is the same the code below:
- myVariable += a;
- Console.WriteLine(myVariable);
- //////////////////////////////////////////////////////////
- //Comparison Operators////////////////////////////////////
- // == : equals to
- //!= : doesn't equal
- //< > : bigger/smaller than
- //<= >= : bigger or equal/smaller or equal than
- //!myBoolVariable : not
- //An example of how to use a comparison operator.
- a = 10;
- b = 5;
- if (a > b)
- {
- Console.WriteLine("a is bigger than b");
- }
- else
- {
- Console.WriteLine("b is bigger than a.");
- }
- //////////////////////////////////////////////////////////
- //Logical Operators///////////////////////////////////////
- //&& : and
- //|| : or
- //An example of how to use a logical operator.
- a = 10;
- b = 5;
- bool myBool = true;
- if ((a > b) && myBool) //Just like in math the expression in the () will be evaluated first.
- {
- Console.WriteLine("a is bigger than b AND myBool is true.");
- }
- //////////////////////////////////////////////////////////
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement