728x90 반응형 전체 글98 C# 람다 Case4 ETC (이벤트 체인에 무명함수 연결) 1. 이벤트 체인에 무명함수 연결 _Tab.SelectedMenuChaged += (s) => { if (_TopbarModel != null) _TopbarModel.SelectedMenu = s; }; 2. Action.add에 함수 추가 _DialogActionQueue.Add(() => CloseWaitInitMessage()); private void CloseWaitInitMessage() { Messagebox.show("OK"); } 3. 함수에 함수연결 public void AAA() => EndMessage("ddd"); private void EndMessage(string _str) { messagebox.show(_str); } 4. 인자값 다른 함수와 연결 void Send(TS.. 2021. 12. 14. C# 람다 Case 3 - list.sort로 정렬하기 List list = new List(); list.Add("a"); list.Add("p"); list.Add("p"); list.Add("l"); list.Add("e"); list.Sort((x, y) => x.CompareTo(y)); foreach (var _list in list) { MessageBox.Show(_list); } 2021. 12. 14. C# 람다 Case2 - 반환형이 델리게이트 리턴 메서드 대체 using System; void Foo(T x) { } void Bar(Action a) { } //Bar (x => Foo (x)); // What type is x? Bar((int x) => Foo(x)); // fix Bar(x => Foo(x)); // Specify type parameter for Bar Bar(Foo); // As above, but with method group; using System; int cnt = 0; Func test = () => cnt++; Console.WriteLine(test()); // 0 Console.WriteLine(test()); // 1 Console.WriteLine(cnt); // 2 int factor = 2; Func multipl.. 2021. 12. 14. C# 람다 Case1 - 기본 단순하게 사용, 리턴값 없이 단순 구문으로 사용 --기존 string GetName(string strName) { return "당신의 이름은 " + strName + "입니다."; } --람다로 변경 string GetName(string strName) => "당신의 이름은 " + strName + "입니다."; --리턴값 없이 단순 구문으로 사용 void PrintName() => Console.WriteLine(GetName("홍길동")); 2021. 12. 14. 이전 1 ··· 8 9 10 11 12 13 14 ··· 25 다음 728x90 반응형