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