Regarding LINQ query syntax...
var foo = new List<int> { 1, 2 };
var boo = from n in foo
where n > 1
select n;
...I always thought this syntax was limited to operating on IEnumerable. Or at least until I learned about IQueryable. And perhaps IObservable as well. But I recently noticed a suggestion that query syntax is based on duck typing. That story didn't look terribly convincing, until I found a site that is dedicated to LINQ to Tasks. LINQ to Tasks looks like it is wholly dependent on duck typing with query syntax!
Ok, what is going on here? Is query syntax using duck typing or not? When I give it a try myself, sure enough this works and appears to prove it's all about duck typing, and not IEnumerable:
public class Joker<T>
{
public T Item;
public Joker(T item)
{
Item = item;
}
}
public static class JokerHelp
{
public static T2 Select<T,T2>(this Joker<T> joke, Func<T,T2> call)
{
return call(joke.Item);
}
}
var oof = new Joker<int>(5);
int foo = from a in oof
select a;
If duck typing is how query syntax works, as is evidently the case, where might be official (MSDN) documentation about this? Or any reasonable documentation?