False order when adding an Item to a list

Hi Community,
I did a script, which adds collision points to make walls. My script (should) actually declare my points in the correct order:
newVerticies.Add(new Vector2(x, y++)); newVerticies.Add(new Vector2(x, y));
When my script runs, the first index is X, Y and then X, Y + 1 for example.
I tried to do solve this with .Insert but I got the same result:
newVerticies.Insert(0,new Vector2(x, y++)); newVerticies.Insert(1,new Vector2(x, y));

If you need a bigger part or the complete script to help, tell me.

I don’t quite understand your problem. Your code does exactly what you get. You use the post-increment operator. That means it first evaluates the current value of the variable and then increment the value.

int i = 3;

int a = i++;   // a == 3
int b = i;     // b == 4

If you use the pre-increment operator the result would be:

int i = 3;

int a = ++i;   // a == 4
int b = i;     // b == 4

Though i have the feeling that you don’t want any of that. I guess you want y+1 in the first index and y in the second. Just do:

newVerticies.Add(new Vector2(x, y+1));
newVerticies.Add(new Vector2(x, y)); 

Note that the value of “y” isn’t changed at all in this case. If you want it to be incremented by one after the two lines you can do

newVerticies.Add(new Vector2(x, y+1));
newVerticies.Add(new Vector2(x, y++)); 

However it’s more clear if you do:

newVerticies.Add(new Vector2(x, y+1));
newVerticies.Add(new Vector2(x, y)); 
y++; // or y += 1;