Unity ref out

ref

public void click()
    {
        int a = 10, b = 10;
        Debug.Log("before a:" + a + " b:" + b);
        get(ref a, b);
        Debug.Log("after a:" + a + " b:" + b);
    }
    public void get(ref int a,int b)
    {
        a = 20;
        b = 20;
    }

Output:
before a:10 b:10
after a:20 b:10

out

也是输出结果的一种 但是感觉ref是实时的(在函数未返回时就会传递)
另外ref需要初始值,out不需要

posted @ 2021-12-31 15:48  小帆敲代码  阅读(47)  评论(0编辑  收藏  举报