Domanda

Sorry I'm new to XNA and C# and I see in tutorials that they initialize their Vector2 variables to Vector2.Zero as soon as they're declared. However there doesn't seem to be any difference when I don't set it to Vector2.Zero and instead I put:

Vector2 vector;

And in the constructor method:

vector = new Vector2(4,4);

Can someone enlighten me on what difference it makes? Thanks!

È stato utile?

Soluzione

Vector2 is a struct. This means that a property or field of that type cannot be set to NULL and therefore will be initialized to a default value.

I suspect your code Vector2 vector; will actually be compiled to Vector2 vector = default(Vector2) which I think will be equal to Vector2.Zero.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top