For me
[Unity] 7) Action<T>, Func<T,T> 본문
Delegate 는 이전에 쓴 글과 같이
대리자로, 특정 매개변수 목록 및 반환 형식이 있는 메서드를 참조를 나타내는 형식으로,
메서드를 다른 메서드에 인수로 전달하는데 사용
Action<T>와Func<T,TResult>
모든 타입의 형태로 미리 정의된 delegate를 간단하게 쓸 수 있도록 하는 기능
// Action<T>
{
public Action<string> testAction;
testAction += TestA;
testAction += Testb;
testAction?.Invoke("Hello");
void TestA(string s)
{
Debug.Log(s + "A");
}
void TestB(string s)
{
Debug.Log(s + "B");
}
}
//Func<T,T>
{
public Func<string,string> testFunc;
testFunc = (str) => {return str;};
Debug.Log(testFunc("HelloFunc"));
}
'Unity > 이론' 카테고리의 다른 글
[Unity] 6) Addressable (0) | 2023.03.03 |
---|---|
[Unity] 5) Nullable (0) | 2023.03.01 |
[Unity] 4) Reflection 과 Attribute (0) | 2023.02.28 |
[Unity] 3) Exception (0) | 2023.02.28 |
[Unity] 2) Delegate 와 Event (0) | 2023.02.28 |