익명 메서드를 만들 때 사용
using System;
delegate int Add(int a, int b);
class CSharp_Practice
{
public static void Main(String[] args)
{
// 람다식 기본형 (대리자 선언)
Add add = (a, b) => a + b;
Console.WriteLine(add(2, 3));
Console.WriteLine("--------------");
// 람다식 Func 대리자
Func<int, int> square = x => x * x;
Console.WriteLine(square(5));
Console.WriteLine("--------------");
// 람다식 Action 대리자
Action<string> hello = name =>
{
string msg = "Hello, " + name;
Console.WriteLine(msg);
};
hello("World!");
}
}
'C#' 카테고리의 다른 글
C# - 동기 및 비동기 처리 (0) | 2024.12.12 |
---|---|
C# - 일반화 (0) | 2024.12.12 |
C# - delegate (대리자) (0) | 2024.12.12 |
C# - Unity 1인칭 게임 구현 [Part. 2] (0) | 2024.12.12 |
C# - Unity 1인칭 게임 구현 [Part. 1] (0) | 2024.12.12 |