public HalloDelegate() { EinfacherDelegate meinDele = EinfacheMethode; Action meinDeleAlsAction = EinfacheMethode; Action meinDeleAlsActionAno = delegate() { Console.WriteLine("Hallo"); }; Action meinDeleAlsActionAno2 = () => { Console.WriteLine("Hallo"); }; Action meinDeleAlsActionAno3 = () => Console.WriteLine("Hallo"); deleMitPara = MethodeMitPara; Action <string> deleMitParaAlsAction = MethodeMitPara; DelegateMitPara deleMitParaAno = (string txt) => { Console.WriteLine(txt); }; DelegateMitPara deleMitParaAno2 = (txt) => Console.WriteLine(txt); DelegateMitPara deleMitParaAno3 = x => Console.WriteLine(x); CalcDelegate calcDele = Multi; Func <int, int, long> calcFunc = Sum; Func <int, int, long> calcFuncAno = (int a, int b) => { return(a + b); }; Func <int, int, long> calcFuncAno2 = (a, b) => { return(a + b); }; Func <int, int, long> calcFuncAno3 = (a, b) => a + b; Predicate <string> immerBool = ImmerBool; List <string> texte = new List <string>(); texte.Where(x => x.StartsWith("b")); texte.Where(Filter); }
public ComposedMission Add(CalcDelegate d) { // add a delegate to the list, that is set in the order added. // we clone the delegate so out mission will not change when the container does. funcList.Add((CalcDelegate)d.Clone()); return(this); }
delegate int CalcDelegate(int a, int b); // 델리게이트를 통해 메세지 원형 정의 void Calc(int a, int b, CalcDelegate calc) { int res = calc(a, b); Console.WriteLine("사용함수 : {0}", calc.Method); Console.WriteLine($"f({a},{b}) = {res}"); }
public HalloDelegate() { EinfacherDelegate dings = EinfacheMethode; Action dingsAlsAction = EinfacheMethode; Action dingsAlsAction2 = delegate() { Console.WriteLine("Hallo"); }; Action dingsAlsAction3 = () => { Console.WriteLine("Hallo"); }; Action dingsAlsAction4 = () => Console.WriteLine("Hallo"); DelegateMitParameter deleMP = ZeigeText; Action <string> deleMPAction = ZeigeText; Action <string> deleMPAction2 = (string x) => Console.WriteLine(x); DelegateMitParameter deleMPAction3 = (x) => Console.WriteLine(x); Action <string> deleMPAction4 = x => Console.WriteLine(x); Action <string> deleMPAction5 = Console.WriteLine; CalcDelegate calcDele = Sum; Func <int, int, long> calcDeleFunc = Sum; CalcDelegate calcDele2 = (int x, int y) => { return(x + y); }; CalcDelegate calcDele3 = (x, y) => x + y; var texte = new List <string>(); var allesWasMitBAnfängt = texte.Where(x => x.StartsWith("b")); var allesWasMitBAnfängt22 = texte.Where(Filter); }
static void Main(string[] args) { GreetingDelegate firstDel, secondDel, thDell; firstDel = new GreetingDelegate(Hello); firstDel("Testing one two three"); secondDel = new GreetingDelegate(GoodBye); secondDel("Bob my good friend"); thDell = new GreetingDelegate(Hello); thDell += secondDel; thDell += firstDel; thDell("hi hi hi"); GreetingDelegatelong longfirst; longfirst = new GreetingDelegatelong(HelloLong); longfirst("bobs", 9); CalcDelegate Calc; Calc = new CalcDelegate(Adds); Calc += new CalcDelegate(sub); Calc(4, 5); }
protected void apress(object sender, EventArgs e) { if (!validinput()) { return; } if (button4.Label == "Cancel") { button4.Label = "Pending"; Globals.cancelled = true; return; } else if (button4.Label == "Pending") { button4.Label = "Cancel"; Globals.cancelled = false; return; } GLib.Timeout.Add(100, new GLib.TimeoutHandler(timerTick)); CalcDelegate cd = RunCalc; button4.Label = "Cancel"; starttime = DateTime.Now; IAsyncResult asyncRes = cd.BeginInvoke(textview1.Buffer.Text, xtext.Buffer.Text, ytext.Buffer.Text, ztext.Buffer.Text, calcprec.Buffer.Text, printprec.Buffer.Text, digitgrp.Active, new AsyncCallback(CalcCallback), null); }
public HalloDelegate() { EinfacheDelegate meineDele = EinfacheMethode; Action meineDeleAlsAction = EinfacheMethode; Action meineDeleAlsActionAno = delegate() { Console.WriteLine("Ich habe keinen Namen"); }; Action meineDeleAlsActionAno2 = () => { Console.WriteLine("Ich habe keinen Namen"); }; Action meineDeleAlsActionAno3 = () => Console.WriteLine("Ich habe keinen Namen"); DelegateMitPara deleMitPara = MethodePara; Action <string> paraAlsAction = MethodePara; DelegateMitPara deleMitParaAno = (string txt) => { Console.WriteLine(txt); }; Action <string> deleMitParaAno2 = (txt) => Console.WriteLine(txt); DelegateMitPara deleMitParaAno3 = x => Console.WriteLine(x); CalcDelegate calcDele = Minus; Func <int, int, long> calcFunc = Sum; CalcDelegate calcDeleAno = (int x, int y) => { return(x + y); }; CalcDelegate calcDeleAno2 = (x, y) => { return(x + y); }; CalcDelegate calcDeleAno3 = (x, y) => x + y; List <string> texte = new List <string>(); texte.Where(x => x.StartsWith("b")); texte.Where(Filter); long res = calcDele.Invoke(56, 23); }
public HalloDelegate() { EinfacherDelegate meinDele = EinfacheMethode; Action meineAction = EinfacheMethode; Action meineActionAno = delegate() { Console.WriteLine("Halölo"); }; Action meineActionAno2 = () => { Console.WriteLine("Hallo"); }; Action meineActionAno3 = () => Console.WriteLine("Hallo"); DelegateMitPara deleMitPara = MethodeMitPara; Action <string> deleMitParaAction = MethodeMitPara; DelegateMitPara deleMitParaAno = (string msg) => { Console.WriteLine(msg); }; DelegateMitPara deleMitParaAno2 = (msg) => Console.WriteLine(msg); DelegateMitPara deleMitParaAno3 = x => Console.WriteLine(x); CalcDelegate calc = Multi; Func <int, int, long> calcFunc = Sum; CalcDelegate calcAno = (x, y) => { return(x + y); }; CalcDelegate calcAno2 = (x, y) => x + y; var text = new List <string>(); text.Where(x => x.StartsWith("b")); text.Where(Filter); long res = calc.Invoke(1, 5); }
static void Main(string[] args) { #region 람다 연습 // 델리게이트 키워드를 사용한 무명메소드 CalcDelegate c1 = delegate(int a, int b) { return(a + b); }; Console.WriteLine(c1(3, 4)); // 람다식으로 표현한 익명메소드 CalcDelegate c2 = (a, b) => a + b; //Delegate에 매개변수가 int 선언이 되어있으므로 생략이 가능 Console.WriteLine(c2(3, 4)); c2 = (a, b) => { if (b == 0) { return(null); } return(a / b); }; Console.WriteLine(c2(10, 3)); Console.WriteLine(c2(10, 0)); #endregion // 2. 제네릭 타입의 델리게이트 참조변수 생성하면서 사칙연산 람다식 할당 Calculator2 <double> c3 = (a, b) => a + b; // 3. 위 참조변수로 Calc 메소드 호출 Calc <double>(3.14, 6.56, c3); Calc <int>(100, 200, (a, b) => a + b); }
public HalloDelegate() { EinfacherDelegate meinDele = HalloWelt; Action meinDeleAlsAction = HalloWelt; Action meinDeleAlsActionAno = delegate() { Console.WriteLine("AAAAHhh"); }; Action meinDeleAlsActionAno2 = () => { Console.WriteLine("AAAAHhh"); }; Action meinDeleAlsActionAno3 = () => Console.WriteLine("AAAAHhh"); DelegateMitPara meinDeleMitPara = HalloWeltMitPara; Action <string> meinDeleMitParaAlsAction = HalloWeltMitPara; DelegateMitPara meinDeleMitParaAno = delegate(string s) { Console.WriteLine(s); }; DelegateMitPara meinDeleMitParaAno2 = (string s) => { Console.WriteLine(s); }; Action <string> meinDeleMitParaAno3 = (s) => Console.WriteLine(s); Action <string> meinDeleMitParaAno4 = x => Console.WriteLine(x); CalcDelegate calcDele = Minus; Func <int, int, long> calcAlsFunc = Sum; CalcDelegate calcDeleAno = (x, y) => { return(x + y); }; CalcDelegate calcDeleAno2 = (x, y) => x + y; List <string> texte = new List <string>(); texte.Where((x) => { return(x.StartsWith("b")); }); texte.Where(x => x.StartsWith("b")); texte.Where(filter); }
public HalloDelegate() { EinfacherDelegate meinDele = EinfacheMethode; EinfacherDelegate meineAno = delegate() { Console.WriteLine("Hallo"); }; Action meinDeleAlsActionAno = () => { Console.WriteLine("Hallo"); }; Action meinDeleAlsActionAno2 = () => Console.WriteLine("Hallo"); Action meinDeleAlsAction = EinfacheMethode; DelegateMitPara deleMitPara = MethodeMitPara; DelegateMitPara deleMitParaAno = delegate(string mmm) { Console.WriteLine(mmm); }; Action <string> deleMitParaAction = MethodeMitPara; DelegateMitPara deleMitParaAno2 = (x) => { Console.WriteLine(x); }; Action <string> deleMitParaAno3 = (x) => Console.WriteLine(x); DelegateMitPara deleMitParaAno4 = x => Console.WriteLine(x); CalcDelegate calcDele = Minus; Func <int, int, long> calcAlsFunc = Minus; CalcDelegate calcDeleFunc = (x, y) => { return(x + y); }; CalcDelegate calcDeleFunc2 = (x, y) => x + y; var lll = new List <string>(); lll.Where(x => x.StartsWith("B")); lll.Where(Filter); }
public static void Main(string[] args) { #region 람다 연습 CalcDelegate calc1 = delegate(int a, int b) { return(a + b); }; Console.WriteLine(calc1(10, 3)); CalcDelegate calc2 = (a, b) => a + b; Console.WriteLine(calc2(10, 3)); CalcDelegate c2 = (a, b) => { if (b == 0) { return(null); } return(a / b); }; if (c2(10, 0) == null) { Console.WriteLine("0으로 나눌 수 없습니다"); } else { Console.WriteLine(c2(10, 0)); } #endregion Calc(1, 2, (a, b) => a + b); Calc(1.2, 2.3, (a, b) => a + b); }
public HalloDelegates() { EinfacherDelegate meinDele; meinDele = EinfacheMethode; meinDele.Invoke(); Action myAction = EinfacheMethode; Action myActionAno = delegate() { Console.WriteLine("AALT"); }; //bis .net 2.0 Action myActionAno2 = () => { Console.WriteLine("Lambda"); }; //ab .net 3 Action myActionAno3 = () => Console.WriteLine("Lambda"); DelegateMitParameter deleMitPara = MethodeMitParameter; Action <string> actionMitPara = MethodeMitParameter; Action <string> actionMitParaAno = (string name) => { Console.WriteLine("Hallo " + name); }; Action <string> actionMitParaAno2 = (name) => Console.WriteLine("Hallo " + name); Action <string> actionMitParaAno3 = x => Console.WriteLine("Hallo " + x); //nur bei 1 parameter CalcDelegate calcDele = Minus; long result = calcDele.Invoke(45, 67); Func <int, int, long> calcAsFunc = Sum; Func <int, int, long> calcAsFuncAno = (int a, int b) => { return(a + b); }; Func <int, int, long> calcAsFuncAno2 = (a, b) => { return(a + b); }; Func <int, int, long> calcAsFuncAno3 = (a, b) => a + b; List <string> texte = new List <string>(); var resultB = texte.Where(x => x.StartsWith("b")); //<-- var resultB2 = texte.Where(Filter); }
public HalloDelegate() { EinfacherDelegate meinDelete = EinfacheMethode; Action meineAction = EinfacheMethode; Action meineActionAno = delegate() { Console.WriteLine("Hallo"); }; Action meineActionAno2 = () => { Console.WriteLine("Hallo"); }; Action meineActionAno3 = () => Console.WriteLine("Hallo"); DelegateMitPara deleMitPara = MethodeMitPara; Action <string> deleMitParaAlsAction = MethodeMitPara; Action <string> deleMitParaAlsAno = (string txt) => { Console.WriteLine(txt); }; Action <string> deleMitParaAlsAno2 = (txt) => Console.WriteLine(txt); Action <string> deleMitParaAlsAno3 = x => Console.WriteLine(x); CalcDelegate calc = Multi; //long rsult = calc.Invoke(4, 6); Func <int, int, long> calcAlsFunc = Sum; CalcDelegate calcAno = (a, b) => { return(a + b); }; CalcDelegate calcAno2 = (a, b) => a + b; List <string> texte = new List <string>(); texte.Where(x => x.StartsWith("b")); texte.Where(Filter); // http://linq101.nilzorblog.com/linq101-lambda.php }
public HalloDelegate() { EinfacheDelegate meineDelegate = EinfacheMethode; Action meinDeleAlsAction = EinfacheMethode; Action meinDeleAlsActionAno = delegate() { Console.WriteLine("Hallooo"); }; Action meinDeleAlsActionAno2 = () => { Console.WriteLine("Hallooo"); }; Action meinDeleAlsActionAno3 = () => Console.WriteLine("Hallooo"); DelegateMitParameter meinDeleMitPara = MethodeMitPara; Action <string> meinDeletMitParaAlsAction = MethodeMitPara; Action <string> meinDeleMitParaAno = (string txt) => { Console.WriteLine(txt); }; Action <string> meinDeleMitParaAno2 = (txt) => Console.WriteLine(txt); Action <string> meinDeleMitParaAno3 = x => Console.WriteLine(x); CalcDelegate calc = Minus; Func <int, int, long> calcAlsFunc = Sum; CalcDelegate calcAno = (int a, int b) => { return(a + b); }; CalcDelegate calcAno2 = (a, b) => { return(a + b); }; CalcDelegate calcAno3 = (a, b) => a + b; long result = calc.Invoke(3, 4); List <string> texte = new List <string>(); List <string> nurB = texte.Where(x => x.StartsWith("b")).ToList(); List <string> nurB2 = texte.Where(Filter).ToList(); foreach (var item in texte) { // if(item.StartsWith("b")) //... } }
static void Main(string[] args) { Mathematics math = new Mathematics(); WorkDelegate work = math.Calculate; // 수학관련 클래스의 메소드를 델리게이트에 저장한다. // 함수포인터처럼 사용할 수 있다. work(10, '+', 5); work(10, '-', 5); work(10, '*', 5); work(10, '/', 5); Console.WriteLine(); // 델리게이트에 각 메소드들을 연산 및 저장으로 인스턴스를 추가한다. // CalcDelegate calc; // 그냥 선언만 해도 되지만 이후 += 연산이 불가능하다. CalcDelegate calc = Add; // 메소드 대입연산이 존재해야 이후 += 인스턴스 추가 가능하다. calc += Sub; calc += Mul; calc += Div; calc(4, 2); // 델리게이트에 저장된 인스턴스들을 모두 실행한다. Console.WriteLine(); calc -= Sub; // 인스턴스를 뺄 수 있다. calc(4, 2); // 남아있는 인스턴스들로만 연산을 한다. }
public static void DelegatesExercise2() { CalcDelegate calDel = new CalcDelegate(Add); calDel += Subtract; calDel += Mult; calDel(2, 4); }
static void Main(string[] args) { CalcDelegate deleg = Calc.Add; Console.WriteLine(deleg(10, 20)); Console.WriteLine($"Delegate Method: {deleg.Method} "); Console.WriteLine($"Delegate Target: {deleg.Target ?? "Empty"} "); }
public void Execute() { outro.X x = new outro.X(); var sum = new CalcDelegate(Sum); var sub = new CalcDelegate(Sub); var mul = new CalcDelegate(Mul); Test.Process(sum); Test.Process(sub); Test.Process(mul); // or Console.WriteLine(sum(6, 6) + sub(4, 10) + mul(10, 10)); // we can also add more func to 1 delegate var allCalcs = sum + sub + mul; Console.WriteLine(allCalcs(10, 10)); }
public static void Process(CalcDelegate c) { Console.WriteLine(c(10, 10)); }