C# 람다식 사용

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
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
using System.IO;
 
namespace ConsoleApplication7
{
    delegate int mydel(int a, int b);
    delegate string mydel2();
    class Program
    {
        static void Main(string[] args)
        {
 
            mydel LamdaTestFuntion = (a, b) => { return (a + b); };
            mydel2 LamdaTestString = () => { return "안녕하세요"; };
 
            System.Console.WriteLine(LamdaTestString());
            System.Console.WriteLine(LamdaTestFuntion(12));
 
            System.Console.ReadLine();
        }
    }
}
 
cs
람다식은 메서드 이름이 존재하지 않기 때문에, delegate를 통해서 사용한다.
델리게이트이름 변수이름 = (매개변수목록) => {메서드의 바디};

댓글

이 블로그의 인기 게시물

[c#] DataTable을 dataGridView에 바인딩

[React] index.html 수정하기

[React] 프로젝트 생성