c# - Are there any interfaces shared by value types representing numbers? -
i able create various structures variable precision. example:
public struct point<t> t : inumber { public t x; public t y; public static point<t> operator +(point<t> p1, point<t> p2) { return new point<t> { x = p1.x+p2.x, y = p1.y+p2.y }; } } i know microsoft deals creating 2 structures - point (for integers) , pointf (for floating point numbers,) if needed byte-based point, or double-precision, you'll required copy lot of old code on , change value types.
there's simple reason why cannot that: operators non-virtual, i.e., compiler must know at compile time whether p1.x+p2.x integer addition or double addition.
Comments
Post a Comment