Here is the original Linq:
var developersUsingCSharp =
from d in developers
where d.Language == "C#"
select d.Name;
This can be written as:
Func<Developer, bool> filteringPredicate = d => d.Language == "C#";
Func<Developer, string> selectionPredicate = d => d.Name;
IEnumerable<string> developersUsingCSharp =
developers
.Where(filteringPredicate)
.Select(selectionPredicate);
Above we have explicitly defined the Func <T,T> delegates. So in
Func<Developer, bool> filteringPredicate = d => d.Language == "C#";
it is known that d is of Developer type and return type is bool. Similarly, for
Func<Developer, string> selectionPredicate = d => d.Name;
it is know that d is of Developer type and the return type is string. However in following valid form of the same query how are these types inferred:
IEnumerable<string> developersUsingCSharp =
developers
.Where(d => d.Language == "C#")
.Select(d => d.Name);
The compiler knows that the elements in
developersareDevelopers, so it can infer the first type argument of both lambdas. The compiler can infer the second type arguments by examining the return values of the lambdas:boolfor theWhere, andstringfor theSelect.