Skip to content

Fibonacci

Taiizor edited this page Mar 1, 2023 · 11 revisions
<title>Fibonacci Class</title>

Fibonacci Class

The Fibonacci class provides methods to generate Fibonacci sequences of different numeric types.

Namespace

The Fibonacci class is defined in the Skylark.Standard.Helper namespace.

Using Statement

The following using statement is required to access the Fibonacci class:

using SHL = Skylark.Helper.Length;
using Skylark.Standard.Helper;

Class Declaration

The Fibonacci class is declared as follows:

public static class Fibonacci
{
    // methods here
}

Methods

The Fibonacci class provides the following methods:

Int Method

The Int method returns an array of Fibonacci numbers as integers.

Declaration

public static int[] Int(int Count = 2);

Parameters

Parameter Description
Count The number of Fibonacci numbers to generate.

Return Value

An array of Count Fibonacci numbers as integers.

Exceptions

The method may throw the following exceptions:

  • System.ArgumentOutOfRangeException: if Count is less than 2 or greater than 47.

Example

int[] fibonacciNumbers = Fibonacci.Int(10);
foreach (int number in fibonacciNumbers)
{
    Console.Write(number + " ");
}
// Output: 0 1 1 2 3 5 8 13 21 34 

IntAsync Method

The IntAsync method asynchronously returns an array of Fibonacci numbers as integers.

Declaration

public static Task<int[]> IntAsync(int Count = 2);

Parameters

Parameter Description
Count The number of Fibonacci numbers to generate.

Return Value

An awaitable task that returns an array of Count Fibonacci numbers as integers.

Exceptions

The method may throw the following exceptions:

  • System.ArgumentOutOfRangeException: if Count is less than 2 or greater than 47.

Example

int[] fibonacciNumbers = await Fibonacci.IntAsync(10);
foreach (int number in fibonacciNumbers)
{
    Console.Write(number + " ");
}
// Output: 0 1 1 2 3 5 8 13 21 34 

Long Method

The Long method returns an array of Fibonacci

Clone this wiki locally