0
What's the difference between i++ and ++i in C# ?
As a begginer at C# I struggle to understand how these two make a difference. I know that theoretically if you write ++i, i gets increased by 1 and then "something" happens but if you write i++ the original value of i gets used on this "something" and then it gets increased by 1 (or at least thats what I think happens). Can someone clarify this to me in a better way or with some examples?
1 Odpowiedź
+ 2
It's the same as in every other language
i++ (first use the value of i than increment it)
++i(first increment the value of i then use)
For example in a loop if i=5 and the loop
uses i++
In first round value is considered as 5 and in second round 6 and so on...
uses ++i
In first round value is considered as 6 and in second round as 7 ....