Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

For me

[Unity] 7) Action<T>, Func<T,T> 본문

Unity/이론

[Unity] 7) Action<T>, Func<T,T>

GiveZero 2023. 3. 3. 11:02

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