If I have a Struct
or a Class
, lets say I'm using a Vector2 (which has two members, float X
and float Y
), how am I supposed to properly get/set its methods in a class?
This is the code I know of right now:
public class MyClass
{
private Vector2 vector; //Has to be private
public Vector2 Vector
{
get { return vector; }
set { vector = value; }
}
}
But what if I wanted to edit the members (or certain members) of the Vector2
with the set
method? Something like this is what I'm asking for:
set.X
{
vector.X = value.X;
}
set.Y
{
vector.Y = value.Y;
}
And it would be called as simply as Vector.X = 5
. I thought up an alternative, using something like public float VectorX { set { vector.X = value; } }
but I would prefer a more logical and object-orientated way. Is there?