Zusammenfassung Delegates, anonyme Methoden usw.
Evolution der Delegates in C#:
delegate void TestDelegate(string s);
TestDelegate testDelA = new TestDelegate(M); //C#1.0 explicite Method M must me declared
TestDelegate testDelB = delegate(string s) { Console.WriteLine(s); }; //C#2.0 inline “anonymos method
TestDelegate testDelC = (x) => { Console.WriteLine(x); }; // C# 3.0. lambda expr.
Action <string> TestDelegate; //C#4.0 DelegateDefinition einfacher //C# 4.0 Actions
In Windows Forms muss eine anonyme Methode noch zu einem MethodInvoker konvertiert werden:
this.Invoke(new MethodInvoker(delegate() { pgbStatus.Minimum = 0; }));
In Wpf zu einer Action:
Application.Current.Dispatcher.Invoke((Action)delegate
{
SetButtonsEnabled(true);
}, null);
Related Posts
No related posts.


