开发者

Forced a Reference Type to be passed by value (or .Clone()d on Pass)

开发者 https://www.devze.com 2023-01-31 21:20 出处:网络
I have a math class (Vector3) that represents the 3 axis (x-y-z) with 3 floats. I would like it to be forced passed as value, not reference, since it\'s really ju开发者_StackOverflow中文版st... A valu

I have a math class (Vector3) that represents the 3 axis (x-y-z) with 3 floats. I would like it to be forced passed as value, not reference, since it's really ju开发者_StackOverflow中文版st... A value, not an object. Any way of doing that automatically? I know I can do .Clone() in each of my methods, but you understand this isn't optimal.


No, you can't do that automatically, because classes are reference types by definition. You have to use a struct if that's what you want.

0

精彩评论

暂无评论...
验证码 换一张
取 消