Posts Tagged ‘delegate’
C# 3.0 delegate 를 좀더 간단하게 표현
using System;
namespace Lamda_ex02
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(Lamda_Test.d1(“Test1″));
Console.WriteLine(Lamda_Test.d2(“Test2″));
Console.WriteLine(Lamda_Test.d3(“Test3″));
}
}
class Lamda_Test
{
// 델리게이트..
public delegate string SomeDelegate(string s);
// C# 1.0
public static SomeDelegate d1 = new SomeDelegate(TestMethod1);
public static string TestMethod1(string s)
{
return s.ToUpper();
}
// C# 2.0
// 익명 타입 클래스 생성이 가능함
public static SomeDelegate d2 = delegate(string s)
{
return s.ToUpper();
};
// C# 3.0
// Lamda 표현이 가능해짐..
public static SomeDelegate d3 = s => s.ToUpper();
}
}







