Skip to Content
C# 3.0: kurz & gut
book

C# 3.0: kurz & gut

by Joseph Albahari, Ben Albahari
May 2008
Intermediate to advanced content levelIntermediate to advanced
248 pages
3h 50m
German
O'Reilly Verlag
Content preview from C# 3.0: kurz & gut

Anonyme Methoden

Anonyme Methoden sind ein Feature aus C# 2.0, das durch die Lambda-Ausdrücke in C# 3.0 ersetzt werden kann. Eine anonyme Methode ist wie ein Lambda-Ausdruck, ihr fehlen aber folgende Eigenschaften:

  • Implizit typisierte Parameter.

  • Ausdruckssyntax (eine anonyme Methode muss immer ein Anweisungsblock sein).

  • Die Möglichkeit, in einen Expression Tree kompiliert zu werden, indem man sie Expression<T> zuweist.

Um eine anonyme Methode zu schreiben, nutzen Sie das Schlüsselwort delegate, gefolgt von einer Parameterdeklaration und einem Methodenrumpf. So könnten wir zum Beispiel für dieses Delegate:

delegate int Transformer (int i);

eine anonyme Funktion wie folgt schreiben und aufrufen:

Transformer sqr = delegate (int x) {return x * x;}; Console.WriteLine ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

How I Built a Personal Board of Directors With GenAI

How I Built a Personal Board of Directors With GenAI

Vipin Gupta
How to Become a Game-Changing Leader

How to Become a Game-Changing Leader

Douglas A. Ready, Alan Mulally
What Successful Project Managers Do

What Successful Project Managers Do

W. Scott Cameron, Jeffrey S. Russell, Edward J. Hoffman, Alexander Laufer

Publisher Resources

ISBN: 9783897215443