Skip to content

KO CSharp Operator Lambda

Codex edited this page Oct 11, 2026 · 2 revisions

Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어

람다식과 본문식

핸드북 C# · 실용 가이드

익명 함수 또는 간결한 표현식 본문 멤버를 선언합니다. 매개변수와 결과 유형은 가능한 경우 컨텍스트에서 추론됩니다.

간단한 예제 (Example.cs)

이 예제를 Example.cs로 따로 저장하고 이 페이지의 다른 예제와 독립적으로 실행하세요.

Example.cs:

// PROJECT-EXAMPLE
System.Func<int, int> twice = value => value * 2;
System.Console.WriteLine(twice(4));

결과:

8

통사론

value => expression / (left, right) => { ... }

예시 1

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;

public static class Program
{
    public static async Task Main(string[] args)
    {
        Func<int, int> square = value => value * value;
        Console.WriteLine(square(4));
    }
}

예시 2

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;

public static class Program
{
    public static async Task Main(string[] args)
    {
        int offset = 3;
        Func<int, int> adjusted = value => { int result = value + offset; return result; };
        Console.WriteLine(adjusted(5));
    }
}

공식 출처: Microsoft 학습.

Clone this wiki locally