Increasing by 1 using Increment Operator, Decreasing By 1 Using Decrement Operator - CSharp Language Basics

CSharp examples for Language Basics:Operator

Description

Increasing by 1 using Increment Operator, Decreasing By 1 Using Decrement Operator

Demo Code

using System;//from ww  w.  j a  va 2  s  . co  m
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program
{
   static void Main(string[] args)
   {
      // Input
      Console.Write("Enter a number: ");
      string input = Console.ReadLine();
      int number = Convert.ToInt32(input);
      // Increasing by 1 using INCREMENT OPERATOR
      number++; // same as number = number + 1;
      Console.WriteLine("Increased by 1: " + number);
      // Decreasing by 1 using DECREMENT OPERATOR
      number--; // same as number = number - 1;
      Console.WriteLine("Back again: " + number);
   }
}

Result


Related Tutorials