ares_games
ares_games

Reputation: 1067

Set Vector2 in XNA

this is obviously a noob question but in XNA is ...

Vector2 a;
Vector2 b;

a = b;

under any circumstances the same as:

a.X = b.X;
a.Y = b.Y;

?

Upvotes: 1

Views: 427

Answers (1)

Cédric Bignon
Cédric Bignon

Reputation: 13022

Vector2 is a struct (which is a value type).

So, if you do a = b.

It means it copies the memory of b into a. It is equivalent to:

a.X = b.X;
a.Y = b.Y;

So, if you do:

b = new Vector2(1, 2);
a = b;
b.X = 5;
Console.WriteLine("a.X = {0}, a.Y = {1}", a);
Console.WriteLine("b.X = {0}, b.Y = {1}", b);

The result is:

a.X = 1, a.Y = 2
b.X = 5, b.Y = 2

Upvotes: 3

Related Questions