深入c# Func委托的详解
深入c# Func委托的详解
发布时间:2016-12-28 来源:查字典编辑
摘要:如下所示:复制代码代码如下:usingSystem;usingSystem.Collections.Generic;usingSystem....

如下所示:

复制代码 代码如下:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace Anonymous_Lam

{

delegate string ConvertMethod(string Method);

class Lambda_Fun

{

static void Main()

{

ConvertMethod ConvertUpperstring = upperCaseString;

Console.WriteLine("Using delegate instance to call upperString method");

Console.WriteLine(ConvertUpperstring("guohu"));

Console.WriteLine("--------------------");

Console.WriteLine("Using anonymous delegate");

ConvertMethod ConvertAsynCaseString = delegate(string s)

{

return s.ToUpper();

};

Console.WriteLine(ConvertAsynCaseString("leihu"));

Console.WriteLine("--------------------");

Console.WriteLine("Using Func<int T,Out TResult>");

Func<string, string> FuncCaseUpper = upperCaseString;

Console.WriteLine(FuncCaseUpper("junwenLi"));

Console.WriteLine("--------------------");

Console.WriteLine("Using anonymous Func<int T,Out TResult>");

Func<string, string> FuncAnonyCaseUpper = delegate(string Name)

{

return Name.ToUpper();

};

Console.WriteLine(FuncAnonyCaseUpper("jinhaoLiu"));

Console.WriteLine("--------------------");

Console.WriteLine("Using lambda Expression");

Func<string, string> FuncLambda = Name => Name.ToUpper();

Console.WriteLine(FuncLambda("chengfan"));

}

static string upperCaseString(string strName)

{

return strName.ToUpper();

}

}

}

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新C#教程学习
热门C#教程学习
编程开发子分类