Subscribe - It's FREE!!

Stay Connected Here

Stay Updated With Us Here



Google

What is the difference between i++ and ++i in C#


Share with WhatsApp


In this post I will share some information about incremental operator ++ of C#. In many interviews this question has been already asked and still it is one of the favorite question for some of the interviewers i.e. What is the difference between i++ and ++I in C#?

So let’s check what the difference is.

In both the cases value of “i” gets incremented but the difference is i++ - It’s a type of post increment. When you write i++ it means “give me the value of i and then increment its value”, on the other hand ++i means “increment the value of i and then give me the updated value”.

Let’s understand using some example.

If you write a code like below.

int i = 2;

int j= 2;

int k = i++;

int l = ++j;

In above case, at the end, values of i,j,k and l will be like following

i = 3

j = 3

k =2

l = 3

So by above example you can easily understand how pre increment and post increment works.

If not and having some queries do share in comment section below. If you have something positive to add this short but useful post then do share that too. Thanks.



If you enjoyed this post take 5 seconds to share it! Be Socialable. :-)

Share with WhatsApp

Posts To Read Next

Top 10 Visual Studio things which can boost developers coding speed

Visual Studio 2012 provides some coding features by which you can code faster if use them properly. This post will cover top 10 things among them to boost your development speed.


Visual Studio 2008 Shell and TFS integration

Visual Studio 2008 Shell and TFS integration is the problem for all newbies of BIDS and TFS. Here is the solution.


How to call click or any event only once in jQuery

Know how to execute an click event or any event only once for any element in jQuery. Perform action only once and even not required to unbind event.


Assembla - Free and private repository to manage your source code online with SVN subversion hosting

With Assembla you can share source code with others online. Free & Private source code repository with SVN Subversion, Git & Perforce Hosting.


Speed up coding in Visual Studio with code snippets & samples at your fingertips

Know how you can speed up coding in Visual Studio with Bing Developer Assistant by having millions of code snippets and sample projects at fingertips.


Your opinion is valuable for us! Comments, suggetions are welcome.


Submit your Email Id to stay updated with us and get notified with our new posts. It's FREE!
We know this popup is disturbing you!
But We would greatly appreciate if you share us with your friends below!

It will not take more than 2 seconds but will motivate us greatly to write more,share more!

x