Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想知道是否可以扩展Microsoft.XNA.Framework.Pointstruct 以使用+、+=和运算-符-=。Microsoft.XNA.Framework.Vector2有大量的运营商,而Point只有最低限度。
Microsoft.XNA.Framework.Point
+
+=
-
-=
Microsoft.XNA.Framework.Vector2
Point
只能从类型的定义中添加这样的运算符重载。您不能将代码中的重载添加到该框架类型。
这是不可能的,但您可以Point像这样向结构添加附加功能:
public static class PointAritmethicExtensions { public static Point Add (this Point a, Point b) { return new Point(a.X + b.X, a.Y + b.Y); } }