Having
public static IEnumerable<long> FibonacciNumbers() {
long current = 0;
long next = 1;
while (true) {
long previous = current;
current = next ;
next = previous + next;
yield return current;
}
}
I can get the first fibonacci numbers less that 100 with
var series = FibonacciNumbers().TakeWhile(num => num < 100);
Just being curious, how would I do that using query syntax ?
You wouldn’t – there’s nothing in C# query expressions that corresponds to
TakeWhile(or Take, Skip, SkipWhile etc). C# query expressions are relatively limited, but cover the biggies:selectandlet)where)fromclauses)orderbyclauses)joinclauses)groupbyclauses)join ... intoclauses)VB 9’s query support is a bit more extensive, but personally I like C#’s approach – it keeps the language relatively simple, but you can still do everything you want via dot notation.