출처 : http://msdn.microsoft.com/en-us/library/bb549151.aspx
기존의 대리자(델리게이트 사용방법)
using System;
delegate string ConvertMethod(string inString);
public class DelegateExample
{
public static void Main()
{
// Instantiate delegate to reference UppercaseString method
ConvertMethod convertMeth = UppercaseString;
string name = "Dakota";
// Use delegate instance to call UppercaseString method
Console.WriteLine(convertMeth(name));
}
private static string UppercaseString(string inputString)
{
return inputString.ToUpper();
}
}위의방법을 더 간단하게 하기위해서 Func(T, Treuslt)를 사용
Func을 이용한방법
using System;
public class GenericFunc
{
public static void Main()
{
// Instantiate delegate to reference UppercaseString method
Func<string, string> convertMethod = UppercaseString;
string name = "Dakota";
// Use delegate instance to call UppercaseString method
Console.WriteLine(convertMethod(name));
}
private static string UppercaseString(string inputString)
{
return inputString.ToUpper();
}
}무기명 메소드에서 사용방법
using System;
public class Anonymous
{
public static void Main()
{
Func<string, string> convert = delegate(string s)
{ return s.ToUpper();};
string name = "Dakota";
Console.WriteLine(convert(name));
}
}람다식에서 사용방법
using System;
public class LambdaExpression
{
public static void Main()
{
Func<string, string> convert = s => s.ToUpper();
string name = "Dakota";
Console.WriteLine(convert(name));
}
}'LINQ & Entity' 카테고리의 다른 글
| [URL]101 LINQ Samples (0) | 2010.04.26 |
|---|---|
| [Attach 메소드]연결되지 않은 엔티티는 제거할 수 없습니다. (0) | 2010.04.09 |
| dataContext 동시에 insert/ update /delete 진행하기 (0) | 2010.04.06 |
| [DataContext.Log] Linq 쿼리 로그보기 (0) | 2010.03.19 |
| [UNION]두 시퀀스 연결(LINQ to SQL) (0) | 2010.02.25 |
| scottgu 아저씨 LINQ 쿼리 모음정리 (0) | 2010.02.23 |
| [LINQ TO SQL] DataContext에서 조인하기 (0) | 2010.02.23 |
| Lambda Expression Example (0) | 2010.02.23 |
| Using LINQ to SQL (0) | 2010.02.23 |
| LINQ 로 Like 검색하기 (0) | 2010.02.19 |