Lambda Expression (람다식)

Lambda Expression


무명함수를 표현할 때 사용되는 식




진행 순서 (소스코드)

1. 기본



2. invoke


3. 무명메소드


4. 명시적 형변환


5. method invoker

TIP)

this.Invoke(delegate {button1.Text = s;} ); //컴파일 에러 발생

MethodInvoker mi = new MethodInvoker(delegate() { button1.Text = s; });

this.Invoke(mi);

//맞는표현

this.Invoke((MethodInvoker) delegate { button1.Text = s; }); //축약된 표현


6. 정리


7. 최종


Lambda : 무명메소드를 더 간결하게 표현, 파라미터가 존재한다면 자료형을 생략 가능


Delegate chain : 연쇄적으로 명시한 method 실행


'SW > C#' 카테고리의 다른 글

Collection method (콜렉션 메소드)  (0) 2017.09.05
LINQ  (0) 2017.09.05
Collection  (0) 2017.09.05

Collection method (콜렉션 메소드)

Collection method


Action<T> : T형태의 파라미터를 받고 리턴 값이 없는 함수에 사용되는 delegate


Func<T, Tresult> : T형태의 파라미터를 받아들이고 리턴타입이 TResult형태로 존재


Predicate<T> : T형태의 파라미터를 받고 리턴타입이 반드시 bool형태



소스코드


1. func


2.변수 선언 생략


3. 람다식 적용


4. 큰 숫자부터 정렬



'SW > C#' 카테고리의 다른 글

Lambda Expression (람다식)  (0) 2017.09.05
LINQ  (0) 2017.09.05
Collection  (0) 2017.09.05

'람다식'에 해당되는 글 2건

1 →