Skip to Main Content
C# 5.0. Leksykon kieszonkowy. Wydanie III
book

C# 5.0. Leksykon kieszonkowy. Wydanie III

by Joseph Albahari, Ben Albahari
September 2013
Intermediate to advanced content levelIntermediate to advanced
208 pages
5h 19m
Polish
Helion
Content preview from C# 5.0. Leksykon kieszonkowy. Wydanie III

Wyrażenia lambda

Wyrażenie lambda (ang. lambda expression) to nienazwana metoda, której kod występuje w miejscu instancji delegatu. Kompilator natychmiast skonwertuje wyrażenie lambda na dwie poniższe konstrukcje:

  • instancję delegatu;

  • drzewo wyrażenia, typu Expression<TDelegate>, przedstawiające kod ujęty w wyrażeniu lambda jako dający się przeglądać, hierarchiczny model obiektowy. Dzięki temu wyrażenia lambda mogą być potem interpretowane w czasie wykonania programu (proces ten został opisany w rozdziale 8. książki C# 5.0 in a Nutshell).

Jeśli mamy dany następujący typ delegatu:

delegate int Transformer (int i);

to możemy do niego przypisać wyrażenie lambda x => x * x i je wywołać; odbywa się to następująco:

Transformer sqr = x => 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

Reinventing the Organization for GenAI and LLMs

Reinventing the Organization for GenAI and LLMs

Ethan Mollick

Publisher Resources

ISBN: 9781457178559