Depending on what you do and why you do it.
Structures in C # are not like classes in Java at all . They are similar to primitive types in terms of speed and semantics. (Actually, primitive types are structures in a sense.) Actually, there is no cost to pass them, so if it optimizes for something that is not a problem, I suggest you simply return the Point method.
However, it is possible that in some cases the transfer of a copy of the structure will be slower if the struct large or this method is a bottleneck, possibly because you call it many times per second (which I doubt it is); in these cases it makes sense to pass them by reference, but first you need to find out if this is really a bottleneck in the first place.
Note, for example, that in the Microsoft XNA library, the Matrix structure has two versions of the same method:
static void CreateLookAt( ref Vector3 cameraPosition, ref Vector3 cameraTarget, ref Vector3 cameraUpVector, out Matrix result) static Matrix CreateLookAt( Vector3 cameraPosition, Vector3 cameraTarget, Vector3 cameraUpVector)
This is purely for performance reasons, but only because this method is called many times per second, and Vector3 slightly larger than a regular struct .
So why exactly did you do this? The answer depends on why you wrote it like this in the first place, but it does not matter for typical code.
source share