Should I Make These Vectors Classes or Structs in C#

Posted by dewald on Stack Overflow See other posts from Stack Overflow or by dewald
Published on 2010-04-18T20:25:55Z Indexed on 2010/04/18 20:33 UTC
Read the original article Hit count: 487

Filed under:
|
|
|
|

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?

© Stack Overflow or respective owner

Related posts about c#

Related posts about struct