The main purpose of "Dot Net Labs" provide the dot net program. You can learn dot net, .Net Core, C#, SQL, Linq step-by-step.

Tuesday 17 January 2017

Increment ++ and Decrement -- Operator as Prefix and Postfix


In this article we will explain Increment ++ and Decrement -- Operator as Prefix and Postfix

Here number1 is variable. number1++ and ++number1 (postfix and prefix) 

number1++ : first assign then increment

Example 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            
            int number1,number2;
           
            number1 = 10;
           
            number2 = number1++;

            Console.WriteLine(number2); 
           
            Console.WriteLine(number1);

            Console.ReadKey();
           
        }
    }
}


Output : 
10
11

++number1 : first increment then assign

Example 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            
            int number1,number2;
           
            number1 = 10;
           
            number2 = ++number1;

            Console.WriteLine(number2); 
           
            Console.WriteLine(number1);

            Console.ReadKey();
           
        }
    }
}

Output : 
10
11


-- number1 : first Decrement then assign

Example 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
           
            int number1,number2;
           
            number1 = 10;
           
            number2 = --number1;

            Console.WriteLine(number2); 
           
            Console.WriteLine(number1);

            Console.ReadKey();
           
        }
    }
}

Output : 
9
9


 number1-- : first assign then Decrement 

Example 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
           
            int number1,number2;
           
            number1 = 10;
           
            number2 = number1--;

            Console.WriteLine(number2); 
           
            Console.WriteLine(number1);

            Console.ReadKey();
           
        }
    }
}

Output : 
10
9







2 comments:

  1. Thank you for this great article which conveyed a good information.keep more updates.
    SEO Company in India

    ReplyDelete
  2. very nice content you shared.
    if you want to know the technologies updates,visit below site.
    http://www.dotnetbasic.com

    ReplyDelete

Do not enter spam link

Popular Posts