开发者

Get and set not working properly

开发者 https://www.devze.com 2023-01-24 15:48 出处:网络
public Vector2 Get() { return var2; } public void 开发者_JS百科Set(Vector2 var1) { var2 = var1; } For some reason if call Get(), var2 is (0, 0)... even though both var 1 X and Y are greater than 0
public Vector2 Get()
{
    return var2;
}

public void 开发者_JS百科Set(Vector2 var1)
{
    var2 = var1;
}

For some reason if call Get(), var2 is (0, 0)... even though both var 1 X and Y are greater than 0...

What am I doing wrong?


The proper syntax for a property in C# is:

public <TYPE_NAME> <PROPERTY_NAME>
{
    get
    {
        return <LOGIC HERE>;
    }
    set
    {
        //value is whatever the property is set to in the calling code
        <local_var, or whatever> = value;
    }
}

Please look stuff like this up on Google first.

0

精彩评论

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