Notice
Recent Posts
Recent Comments
Link
반응형
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- 디지털트윈
- 유니티
- 드롭다운
- Simulation
- C#
- 최소신장트리 mst
- 오블완
- 너비탐색
- readonly
- 행동트리
- navisworks api
- 유니티 sparkmain(clone)
- dropdown
- 트리구조
- 깊이탐색
- unity sparkmain(clone)
- raycast
- 크루스칼
- GetComponent
- list clear
- 티스토리챌린지
- sparkmain(clone)
- articulation body
- dfs
- 습관형성 #직장인자기계발 #오공완
- Unity
- 최단거리 알고리즘
- removeAll
- unity korea
- sparkmain(clone) 무한생성
Archives
- Today
- Total
낑깡의 게임 프로그래밍 도전기
C# 람다식(Lamba) 본문
반응형
Func<int, bool> func = (int actorCount) =>
{
Console.WriteLine();
return actorCount > 1000;
};
=>
화살표 뒤에는 리턴값이 된다.
private static void PrintActorCount(int actorCount)
{
Console.WriteLine(actorCount);
}
private static bool IsActorCountCheck(int actorCount)
{
if(actorCount > 1000)
return true;
return false;
}
이것을 람다식으로 만들면 아래 처럼 된다.
private static void PrintActorCount(int actorCount) => Console.WriteLine(actorCount);
private static bool Is ActorCount(int actorCount) => actorCount > 1000;
액션 델리게이트와 관련지어 살펴보면
//Action<int> action = PrintActorCount;
Action<int> action = (int actorCount) => Console.WriteLine(actorCount);
이렇게 줄여줄 수 있다.
Action<int> action = (actorCount) => Console.WriteLine(actorCount);
자료형 int를 뺴도 된다 들어오는 향식이 int라서 뺄수 있다.
여러줄 쓰는 법
Action<int> action = (int actorCount) => {
Console.WriteLine(actorCount);
};
Func 델리게이트 람다로 바꾸기
//Func<int, bool> func = ISActorCountCheck;
Func<int, bool> func = (int actorCount) => actorCount > 1000;
여러줄로도 쓸 수 있으나 그럼 return 값을 넣어 줘야한다.
private static void PrintActorCount(int actorCount)
{
Console.WriteLine(actorCount);
}
private static void SendServer(Action<int> action)
{
Console.WriteLine("서버 요청");
Console.WriteLine("서버 요청 도착 actorCount : 3000");
action(3000);
}
SendServer(PrintActorCount);
이것을 아래 처럼 해 줄 수 있다.
SendServer((actorCount) => Console.WriteLine(actorCount));
private static void SendServer(Action<int> action)
{
Console.WriteLine("서버 요청");
Console.WriteLine("서버 요청 도착 actorCount : 3000");
action(3000);
}
반응형
'C#' 카테고리의 다른 글
| c# 제네릭(Generic) (2) | 2025.07.27 |
|---|---|
| C# 링큐(Linq) (3) | 2025.07.26 |
| C# 서브클래스, 인터페이스, 추상클래스 (1) | 2025.07.24 |
| C# static, deepcopy (1) | 2025.07.23 |
| C# 의존성 주입(Dependency Injection, DI) (1) | 2025.07.22 |