Closed olee closed 3 years ago
Hello! The point of this ref is to explicitly show that the parameter will be modified inside the method. While it indeed can be omitted, without it you will have to look at the source code to understand what is happening. And the performance overhead (if it even exists) is insignificant. It is not a very common pattern, but it is useful to experss the intent behind the method.
Though then I'd say to rather make the intent clear through naming the function properly like AssignToMesh(Mesh mesh)
or something like that?
However using a ref here prevents using this function in some places which is why I had to rewrite it locally which I don't think is enough to leave out the stylistic ref usage there.
What was your use case? Can you provide an example?
MeshDraft.ToMesh(ref Mesh mesh)
could be fully replaced withMeshDraft.ToMesh(Mesh mesh)
. There is no use to use any ref here and it just makes code more ineffective and unintuitive.