static void Main(string[] args) { LambdaTest sqr = (x, y) => x * y; //Console.WriteLine(sqr(2,4)); // 100 //Action<int> action = (a) => Console.WriteLine(a * a); //action(10); // 100 ((Action <int>)((a) => Console.WriteLine(a * a)))(10); Predicate <int> predicate = (a) => { return(a == 2); }; //Console.WriteLine(predicate(4)); //Func<int, int, int> func = (a, b) => a * b; //Console.WriteLine(func(4,4)); //Anonymous function Console.WriteLine(((Func <int, int, int>)((a, b) => { return(a * b); }))(20, 20)); Calculator calculator = new Calculator(); calculator.Minus(2, 1); int i = 10; Console.WriteLine(i.IsGreaterThan(100)); DelelegateTesting delelegateTesting = new DelelegateTesting(); delelegateTesting.LongRunningFunction(CallBack); Console.ReadLine(); void CallBack() { Console.WriteLine("I am Finished now !"); } }
static void Main(string[] args) { LambdaTest.CreateList(); Console.Write(LambdaTest.GetHeader()); Console.WriteLine($"{Environment.NewLine}First test finalized on {DateTime.Now.ToShortTimeString()} {Environment.NewLine}" + $"RESULT> {Environment.NewLine}{LambdaTest.LambdaDirectCall()}"); Console.WriteLine($"{Environment.NewLine}Second test finalized on {DateTime.Now.ToShortTimeString()} {Environment.NewLine}" + $"RESULT> {Environment.NewLine}{LambdaTest.LambdaCompiledCache()}"); //Console.WriteLine($"{Environment.NewLine}Third test finalized on {DateTime.Now.ToShortTimeString()} {Environment.NewLine}" + // $"RESULT> {Environment.NewLine}{LambdaTest.LambdaCompiled()}"); Console.WriteLine($"{Environment.NewLine}Four test finalized on {DateTime.Now.ToShortTimeString()} {Environment.NewLine}" + $"RESULT> {Environment.NewLine}{LambdaTest.LambdaGeneratedCache()}"); Console.WriteLine($"{Environment.NewLine}Fifth test finalized on {DateTime.Now.ToShortTimeString()} {Environment.NewLine}" + $"RESULT> {Environment.NewLine}{LambdaTest.LambdaGenerated()}"); Console.ReadKey(); }
static void Main(string[] args) { /* * Review delegate * Lambda * yield */ // Create delegate object // DelegateAction parameter: intellisense "void () target", what is mean? // 교과서적인 문법 DelegateAction da = new DelegateAction(DelegateActionMethod); da.Invoke(); DelegateAction da2 = DelegateActionMethod; da2(); DelegateAction3 da10 = new DelegateAction3(DelegateActionMethod10); int returnValue = da10(10, "apple"); DelegateActionMethod(); Test test = new Test(); Test.DelegateAction delegateAction = new Test.DelegateAction(DelegateActionMethod); test.SetDelegate(delegateAction); Store s = new Store(); Customer c = new Customer(); s.PayEvent1 = c.Pay; // event의 정체: delegate type으로 동작하는 특수한 기능 //Button button = new Button(); //button.Click += Button_Click; // Lambda DelegateAction da3 = () => Console.WriteLine("Called da2 delegate variable."); // delegate를 표현하는 문법 LambdaTest lambda = () => { }; // parameter 하나를 받는 표현은 () 생략이 가능, 구현부분도 1줄이면 {} 생략 가능 LambdaTest2 lambda2 = value => value = 1; // 평소에 봤던 lambda들... List <int> list = new List <int>(); int findItem = list.Find(obj => obj == 10); var result = list.Where(obj => obj > 10); foreach (var item in list) { } // yield foreach (var item in GetNames) { if (item != null) { Console.WriteLine("AOA member: " + item); } } #region 요청 리뷰 // 1. LINQ // 2. Design pattern: Factory, Starategy #endregion }