C# 8.0 Pocket Reference by Joseph Albahari

C# 8.0 Pocket Reference by Joseph Albahari

Author:Joseph Albahari
Language: eng
Format: epub
Publisher: O'Reilly Media
Published: 2019-11-18T16:00:00+00:00


x => { return x * x; };

Lambda expressions are used most commonly with the Func and Action delegates, so you will most often see our earlier expression written as follows:

Func<int,int> sqr = x => x * x;

The compiler can usually infer the type of lambda parameters contextually. When this is not the case, you can specify parameter types explicitly:

Func<int,int> sqr = (int x) => x * x;

Here’s an example of an expression that accepts two parameters:

Func<string,string,int> totalLength = (s1, s2) => s1.Length + s2.Length; int total = totalLength ("hello", "world"); // total=10;

Assuming Clicked is an event of type EventHandler, the following attaches an event handler via a lambda expression:



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.