C # / XNA Installation Instance Properties

I am doing an extension for the Vector2 class. In my main code, I can say

Vector2 v=new Vector2();
v.X=2;

But in my extension I can’t.

public static void SetToThree(this Vector2 vector)
{
    vector.X=3;       
}

v.SetToThree () does not change v. When I go through the line through the code, in the extension vector X, the direction changes to 3, but after the extension was completed and the main code continued, v did not change at all. Is there a way for the SetToThree extension method to change the value of v?

+3
source share
1 answer

, , - arg0 (this) ref - , . ref , return:

public static Vector2 SetToThree(this Vector2 vector)
{
    vector.X=3;
    return vector;
}

:

v = v.SetToThree();

, , ...

+4

Source: https://habr.com/ru/post/1743580/


All Articles