C
C#2h ago
Attikitty

✅ Basic Design Question on Vectors

As a learning project I wanted to implement some basic vector data types. I had made a rudimentary Vector2D and Vector3D class, and was making dynamically sized Vector class when I had this question. Would it be possible to have a statically sized vector class that can work with multiple sizes? For example, I could create an instance of VectorN with 2 dimensions and an instance of VectorN with 5 dimensions and if I tried to add them it would error in compile time. With my very introductory knowledge of C# my best guess is with attributes and reflection, but I'm not sure and thought I'd ask.
1 Reply
Attikitty
AttikittyOP2h ago
another example would be if I made a method that only can take in vector arguments with a certain amount of dimensions like ik once im in a method i could manually check using if statements but that wouldn't detect things during compiling to my knowledge the only way i can think of is making individual classes for each dimension and then have them all extend the same interface but thats not exactly what i want

Did you find this page helpful?