How to: create a sequence of fibonacci numbers

You can create sequences from everything using the FunctionBasedSequence class. You only need a method that matches to the Func<Integer, T> delegate.

This code sample enumerates the first n fibonacci numbers:
foreach (
    Integer i in new FunctionBasedSequence<Integer>() {
        Function = NumberTheory.FibonnaciNumber
    }.Take(n)
)
    Console.WriteLine(i);

Last edited May 10, 2010 at 1:08 PM by BlueCode, version 1

Comments

No comments yet.