In my opinion, this depends on the implementation of Point3.Equals ().
Consider the following code:
Dictionary<Point3, string> cache; Point3 pointA = new Point3(1, 2, 3); Point3 pointB = new Point3(1, 2, 3); cached[pointA] = "Value Aaa"; cached[pointB] = "Value Bbb"; Console.WriteLine(cached[pointA]); Console.WriteLine(cached[pointB]);
If Point3 has reference semantics (pointA.Equals (pointB) when they are the same object), this will output:
Value Aaa Value Bbb
If Point3 has semantics of values ββ(pointA.Equals (pointB) when their x, y, and z values ββare equal), this will output:
Value Bbb Value Bbb
With semantics of meaning, it doesn't really matter if you create a new object or not. Perhaps you just return the same to avoid creating garbage.
If your type has reference semantics, you probably want the unary plus to create a new object, so that it behaves just like other operators.
source share