C#: Examples of lambda expressions with explicit return types.

This commit is contained in:
Michael Nebel
2022-01-26 15:41:31 +01:00
parent 25019dbaa0
commit 83a5ef4961

View File

@@ -4,8 +4,17 @@ public class Lambda
{
public void M1()
{
// Examples need for implicitly typed lambdas.
Func<int, string> f1 = (int x) => x.ToString();
var f2 = (int x) => x.ToString();
// Examples need for explicit return type for implicitly and explicitly typed lambda.
var f3 = object (bool b) => b ? "1" : 0;
Func<bool, object> f4 = object (bool b) => b ? "1" : 0;
// Examples needed for explicit return type for downcast.
var f5 = int (bool b) => b ? 1 : 0;
var f6 = object (bool b) => b ? 1 : 0;
}
}