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

This method returns an array of long type Fibonacci numbers up to the specified count. The count must be between 2 and 93, inclusive.

Parameters

  • Count (optional): The number of Fibonacci numbers to generate. Defaults to 2.

Returns

An array of long type Fibonacci numbers.

Examples

Get the first 10 Fibonacci numbers:

long[] result = Skylark.Standard.Helper.Fibonacci.Long(10);
	// result: [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]

LongAsync Method

This method is the asynchronous version of Long method. It returns a task that generates an array of long type Fibonacci numbers up to the specified count. The count must be between 2 and 93, inclusive.

Parameters

  • Count (optional): The number of Fibonacci numbers to generate. Defaults to 2.

Returns

A task that generates an array of long type Fibonacci numbers.

Examples

Get the first 10 Fibonacci numbers asynchronously:

long[] result = await Skylark.Standard.Helper.Fibonacci.LongAsync(10);
	// result: [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]

Decimal Method

This method returns an array of decimal type Fibonacci numbers up to the specified count. The count must be between 2 and 140, inclusive.

Parameters

  • Count (optional): The number of Fibonacci numbers to generate. Defaults to 2.

Returns

An array of decimal type Fibonacci numbers.

Examples

Get the first 10 Fibonacci numbers:

decimal[] result = Skylark.Standard.Helper.Fibonacci.Decimal(10);
	// result: [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]

DecimalAsync Method

This method is the asynchronous version of Decimal method. It returns a task that generates an array of decimal type Fibonacci numbers up to the specified count. The count must be between 2 and 140, inclusive.

Parameters

  • Count (optional): The number of Fibonacci numbers to generate. Defaults to 2.

Returns

A task that generates an array of decimal type Fibonacci numbers.

Examples

Get the first 10 Fibonacci numbers asynchronously:

decimal[] result = await Skylark.Standard.Helper.Fibonacci.DecimalAsync(10);

Get the first 20 Fibonacci numbers synchronously:

long[] result = Skylark.Standard.Helper.Fibonacci.Long(20);

Get the first 30 Fibonacci numbers asynchronously:

int[] result = await Skylark.Standard.Helper.Fibonacci.IntAsync(30);
Clone this wiki locally