How to write a LINQ Expression (method call syntax preferred) that gives a list of fibonacci numbers lying within a certain range, say 1 to 1000 ?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
Here is enumerator base solution. Its a lazy evaluation. So next number is generated when MoveNext() is done.
OK; for a more "FP" answer:
Note that in theory this can be written as a single lambda, but that is very hard.
late, but a fast version with the "yield" keyword :-)
Easiest way to print fibonacci using linq
Using the iterator-block answer from here:
or for a list:
Output:
not very performant: