Should I Make These Vectors Classes or Structs in C#
- by dewald
I am creating a geometry library in C# and I will need the following immutable types:
Vector2f (2 floats - 8 bytes)
Vector2d (2 doubles - 16 bytes)
Vector3f (3 floats - 12 bytes)
Vector3d (3 doubles - 24 bytes)
Vector4f (4 floats - 16 bytes)
Vector4d (4 doubles - 32 bytes)
I am trying to determine whether to make them structs or classes. MSDN suggests only using a struct if the size if going to be no greater than 16 bytes. That reference seems to be from 2005. Is 16 bytes still the max suggested size?
I am sure that using structs for the float vectors would be more efficient than using a class, but what should I do about the double vectors? Should I make them structs also to be consistent, or should I make them classes?