Answer the question
In order to leave comments, you need to log in
Vector from float with operator inheritance in C#?
I need a data type with three float fields and at the same time without rewriting operators, that is
class Vector{ float X,Y,Z; }
operator+(vector A, vector B){ A.X += B.X; A.Y += B.Y;... }
Vector a,b,c;
c = a + b;
Vector a,b,c;
c.x = a.x + b.x;
c.y = a.y + b.y;
c.z = a.z + b.z;
Answer the question
In order to leave comments, you need to log in
It seems impossible to do without redefining operators. How to override can be seen here
C# doesn't work like that, how can the compiler know what your class is and what should happen when adding? All operators need to be implemented by yourself. Writing three methods is a matter of a couple of minutes, you went to the toaster for longer. If the version of dotnet does not allow the use of built-in classes, you can peep the implementation in the Reference Source:
referencesource.microsoft.com/#System.Numerics/Sys...
referencesource.microsoft.com/#System.Numerics/Sys...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question