728x90
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NewBehaviourScript : MonoBehaviour
{
int a = 5;
int b = 4;
int sum;
void Add()
{
sum = a + b;
}
void Back()
{
sum = 0;
}
delegate void MyDelegate<T>(T a,T b);
MyDelegate myDelegate;
// Start is called before the first frame update
void Start()
{
myDelegate = Add;
// 무명 메소드
myDelegate += delegate(){print(sum);};
// 람다식 매개변수
myDelegate += (int a, int b) => print(sum);
myDelegate(3,5);
myDelegate += Back;
myDelegate();
}
// Update is called once per frame
void Update()
{
}
}
728x90
'유니티로 배우는 c#' 카테고리의 다른 글
예외 처리 (0) | 2021.10.11 |
---|---|
Action과 Func (0) | 2021.10.11 |
형식 매개 변수 T (0) | 2021.10.10 |
인터페이스 (0) | 2021.10.10 |
인덱서 (0) | 2021.10.10 |