c# - Changing values in place instead of creating new instances -
Actually I have checked Xena and some slimdex (prompt :)), which has lots of straics. Methods that look like this:
Public static vector 3 operator + (vector 3a, vector 3b) Where to look like stuff:
vector 3c = new vector 3 (...) I'm wondering if it just makes sense:
ax + = bx ... back one obviously # 1 over Looks good / fair, but # 2 is not a new vector 3 which is faster.
I think it's fast and clear, if not as clear as # 1.
Which is better? Have a problem with # 2?
The only problem with 2 is that, because vector 3 is a value type (for good reason , See details), when you are part of a collection or used as a property member, you can not edit it. For example, it is very common for the list to list & lt; Vector3 & gt; Member, but if you do:
myList [150] .X + = ...; This fails, because the indexer gives a new straight (value type symmetry) it is usually secured with the value types so that they can be behaved irreversibly, for which your The first syntax is required.
Comments
Post a Comment