By 22/07/2015 12 Comments

C# Operators

  • An operator is a special symbol which performs an operation / action on one or multiple numeric values.
  • An operator can change the variable values or produce new values.
  • Any variable which is involved in operation is called an operand, if there are more than 1 variable that are called operands.
  • If any operator performs an action on more than one operands (variables) that operator is called a binary operator.

C# provides following built-in operators:

  • Arithmetic operators
  • Assignment / compound operators
  • Relational / comparison operators
  • Logical operators
  • Bitwise operators

Example:

using System;
namespace csharpBasic
{
  // Start class definition / declaration.
    class Program
    {
      // Static main method void type declaration.
        static void Main(string[] args)
        {
          // Declare and initialize v1 and v2 int type variables with 5,5 values.
            int v1 = 5, v2 = 5;

          // Declare an int type variable result.
            int result;

          // Perform Addition between v1 and v2, assign result to (result) variable.
            result = v1 + v2;

          // Print (result) variable which is 10
            Console.WriteLine("Plus: {0} ", result);

          // Initialize and declare number variable of an int type with value of 3.
            int number = 3;

          // This line is called an expression which adds 3 to (number) variable.
            number += 3;

          // Print number variable.
            Console.WriteLine("Addition assignment: {0} ", number);

          // Declare a bool type.
            bool result1;

          // An expression which compares v1 and v2 values using an equal to operator.
            result1 = (v1 == v2);

          // Print result1 variable.
            Console.WriteLine("Relational == operator: {0} ", result1);

          // Perform short-circuit OR operation.
            result1 = (v2 == 10) || (v2 == 1); 
     
          // Print result1 variable.
           Console.WriteLine("Logical Short-circuit OR (||): {0} ", result1); 
           Console.ReadKey(); 
        } // End of main method definition. 
     } // End of class. 
 }






Next Tutorial →


← Previous Tutorial


Posted in: C# Basics, C#.NET

Leave your valuable Comment

Have a natural attraction for women cosmetics and replica watches uk clothes, no
more than two for men the most attractive one, is to make their own driving experience, happy and can serve as the facade of the car, another is to highlight the taste edify sentiment rolex replica watch. The replica rolex is undoubtedly the most fashionable accessories, wear a suit to attend the activities, but also get a decent match on the replica watches .