Click here to Skip to main content
15,887,135 members
Home / Discussions / C#
   

C#

 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
N8tiv28-Apr-13 21:33
N8tiv28-Apr-13 21:33 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
Keld Ølykke28-Apr-13 20:34
Keld Ølykke28-Apr-13 20:34 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
N8tiv28-Apr-13 22:11
N8tiv28-Apr-13 22:11 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
harold aptroot28-Apr-13 22:20
harold aptroot28-Apr-13 22:20 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
N8tiv28-Apr-13 22:35
N8tiv28-Apr-13 22:35 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
harold aptroot28-Apr-13 22:42
harold aptroot28-Apr-13 22:42 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
N8tiv28-Apr-13 22:54
N8tiv28-Apr-13 22:54 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
OriginalGriff28-Apr-13 23:39
mveOriginalGriff28-Apr-13 23:39 
It's pretty simple:
C#
int x = 10;
int y = 100;
int z = y;

At the end of this, you have three variables, each with separate values:
 x     y     z
10    100   100
Although "y" and "z" contain the same number, they aren't linked together, so changing one does not change the other. Think of them as three pockets: two in your trousers, and one in your shirt. If you put ten coins in each pocket, they all have the same number. If you then take 5 coins out of your shirt pocket, you still have ten coins in each of your trouser pockets.
C#
y = y++ + x;
Equates to:
C#
int y2 = y;
y = y + 1;
y = y2 + x;

Which means that "y" ends up holding 110 - as you have seen.
C#
z = ++z + x;
Is the equivalent of:
C#
int z2 = z + 1;
z = z2 + x;
Which is the same as saying:
C#
z = 11 + 100;
Which gives you the answer: 111
The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)

GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
N8tiv28-Apr-13 23:47
N8tiv28-Apr-13 23:47 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
OriginalGriff29-Apr-13 0:33
mveOriginalGriff29-Apr-13 0:33 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
N8tiv30-Apr-13 19:04
N8tiv30-Apr-13 19:04 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
OriginalGriff30-Apr-13 21:57
mveOriginalGriff30-Apr-13 21:57 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
N8tiv30-Apr-13 23:02
N8tiv30-Apr-13 23:02 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
OriginalGriff30-Apr-13 23:36
mveOriginalGriff30-Apr-13 23:36 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
N8tiv4-May-13 22:31
N8tiv4-May-13 22:31 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
OriginalGriff4-May-13 22:50
mveOriginalGriff4-May-13 22:50 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
N8tiv4-May-13 23:02
N8tiv4-May-13 23:02 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
OriginalGriff4-May-13 23:14
mveOriginalGriff4-May-13 23:14 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
N8tiv4-May-13 23:48
N8tiv4-May-13 23:48 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
OriginalGriff4-May-13 23:58
mveOriginalGriff4-May-13 23:58 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
N8tiv5-May-13 0:04
N8tiv5-May-13 0:04 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
OriginalGriff5-May-13 0:11
mveOriginalGriff5-May-13 0:11 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
N8tiv5-May-13 0:17
N8tiv5-May-13 0:17 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
N8tiv5-May-13 0:19
N8tiv5-May-13 0:19 
GeneralRe: Incrementing and Decrementing - Just Trying to Understand Pin
N8tiv5-May-13 0:05
N8tiv5-May-13 0:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.