C # The extension method is derived from the "delegate extension" and "recursive delegate" by the Fibonacci series"

Source: Internet
Author: User

First, review the concept of a Series: the number of columns in a certain order is called a series... (see Baidu Encyclopedia: Series)
Several simple series:
1, 1, 1, 1, 1, 1, 1... // series 1
0, 1, 2, 3, 4, 5, 6, 7... // series 2
0, 1, 4, 9, 16, 25, 36, 49... // series 3
Definition of the generic formula: the relationship between the nth item of the series and the ordinal number of the items, that is, the generation algorithm of the series.
The above several series can be expressed
An = F (n) = 1
An = F (n) = n
An = F (n) = n * n

With the sequence and the definition of the formula, our task is described as follows:
Use the simplest code to describe the generic formula, and use the simplest algorithm to generate the first N numbers of series.

Under this requirement, the General Code cannot be concise. Here we use lambda expressions to describe the general formula:

// The general formula of Series 1
Public static Func <int, int> fun1 = n => 1;
// Expression of Series 2
Public static Func <int, int> fun2 = n => n;
// Three-way formula of Series
Public static Func <int, int> fun3 = n => n * n;

 

Does lambda expression look like a mathematical formula!

Let's look at the generation algorithm. Here we use an unusual extension:
 

/** // <Summary>
/// Generate the first count of the queue
/// </Summary>
/// <Param name = "func"> generic formula </param>
/// <Param name = "count"> quantity generated </param>
/// <Returns> count before the queue </returns>
Public
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.