ref 참조 / bool 형 메소드에서 매개변수로 복제 하지 않고 받아오기
using UnityEngine;
using System.Collections;
public class test : MonoBehaviour
{
bool testType = true;
void TestMethod(bool type)
{
type = false;
Debug.Log(testType); // 복제가 되어 다른 변수가 되므로 true
}
void TestMethodRef(ref bool type)
{
type = false;
Debug.Log(testType); // ref(참조) 선언으로 원래 변수 그대로 사용 하므로 false
}
void Start()
{
TestMethod(testType);
TestMethodRef(ref testType);
}
}
using System.Collections;
public class test : MonoBehaviour
{
bool testType = true;
void TestMethod(bool type)
{
type = false;
Debug.Log(testType); // 복제가 되어 다른 변수가 되므로 true
}
void TestMethodRef(ref bool type)
{
type = false;
Debug.Log(testType); // ref(참조) 선언으로 원래 변수 그대로 사용 하므로 false
}
void Start()
{
TestMethod(testType);
TestMethodRef(ref testType);
}
}
ref 설명
https://msdn.microsoft.com/ko-kr/library/14akc2c7.aspx
댓글
댓글 쓰기