function program小试
using System;
namespace ConsoleApplication1.FPTest
{
/// <summary>
/// FPTest 的摘要说明。
/// </summary>
public class FPTest
{
public static void Main(){
FPTest t = new FPTest();
Console.WriteLine(t.Sum(new Term(t.Cube),1,new Next(t.Inc),4).ToString());
}
public FPTest()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public delegate Int32 Term(Int32 x);
public delegate Int32 Next(Int32 n);
public delegate Object MyParse(String result);
public Object Int32Parse(String result){
return Int32.Parse(result);
}
public void Change(MyParse parse,String result){
//
Console.WriteLine(parse(result));
}
public Int32 Sum(Term term,Int32 a, Next next,Int32 b){
if (a>b)
return 0;
else{
return term(a) + Sum(term,next(a),next,b);
}
}
private Int32 Inc(Int32 n){
return n + 1;
}
private Int32 Cube(Int32 x){
return x*x*x;
}
}
}
namespace ConsoleApplication1.FPTest
{
/// <summary>
/// FPTest 的摘要说明。
/// </summary>
public class FPTest
{
public static void Main(){
FPTest t = new FPTest();
Console.WriteLine(t.Sum(new Term(t.Cube),1,new Next(t.Inc),4).ToString());
}
public FPTest()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public delegate Int32 Term(Int32 x);
public delegate Int32 Next(Int32 n);
public delegate Object MyParse(String result);
public Object Int32Parse(String result){
return Int32.Parse(result);
}
public void Change(MyParse parse,String result){
//
Console.WriteLine(parse(result));
}
public Int32 Sum(Term term,Int32 a, Next next,Int32 b){
if (a>b)
return 0;
else{
return term(a) + Sum(term,next(a),next,b);
}
}
private Int32 Inc(Int32 n){
return n + 1;
}
private Int32 Cube(Int32 x){
return x*x*x;
}
}
}