I’m developing a middle sized project, where performans is really important. I could not find (actually can not understand) the difference between static and extension functions.
e.g:
public static class My
{
public static Vector2 MyTransform(this Vector2 point, float Rotation)
{
//....
return MyVector;
}
public static Vector2 MyTransform(Vector2 point, float Rotation)
{
//....
return MyVector;
}
}
These functions are used same only extension function is called over its instance:
- Vector2 calc = myVector.MyTransform(0.45f);
- Vector2 calc = My.MyTransform(myVector, 0.45f)
Which one do you prefer to use, or is prefered to use and why ?
Thanks !
There will be no difference in performance – a call to the extension method of
will simply be converted by the compiler into:
Now that’s not to say that extension methods should be used everywhere – but it looks like this is an appropriate use case, unless you could actually make it an instance method on Rotation:
(As an aside, I’d strongly urge you to reconsider your names, in order to follow .NET naming conventions.)