C#은 포인터가 없기 때문에 매개변수로 값 전달 시 ref를 선언해주면 변수의 주소의 값을 접근 할 수 있다.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Test : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        int val1 = 1;
        int val2 = 2;

        Swap(ref val1, ref val2);
        print("val1=" + val1 + "," + "val2=" + val2);
    }

    void Swap(ref int a, ref int b)
    {
        int temp = a;
        a = b;
        b = temp;
    }
}

출력 결과

va1=2, val2=1
Posted by 소블리애
,