深入c# Func委托的詳解
更新時(shí)間:2013年06月09日 09:45:20 作者:
本篇文章是對(duì)c#中的Func委托進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
如下所示:
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();
}
}
}
復(fù)制代碼 代碼如下:
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();
}
}
}
相關(guān)文章
C# WinForm程序設(shè)計(jì)簡(jiǎn)單計(jì)算器
這篇文章主要為大家詳細(xì)介紹了C# WinForm程序設(shè)計(jì)簡(jiǎn)單計(jì)算器,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-02-02
C#關(guān)于System.Collections空間詳解
這篇文章主要介紹了C#關(guān)于System.Collections空間,需要的朋友可以參考下2014-07-07
C# Web應(yīng)用調(diào)試開(kāi)啟外部訪問(wèn)步驟解析
本文主要介紹了C# Web應(yīng)用調(diào)試開(kāi)啟外部訪問(wèn)的實(shí)現(xiàn)過(guò)程與方法。具有一定的參考價(jià)值,下面跟著小編一起來(lái)看下吧2017-01-01
C#中私有構(gòu)造函數(shù)的特點(diǎn)和用途實(shí)例解析
這篇文章主要介紹了C#中私有構(gòu)造函數(shù)的特點(diǎn)和用途,需要的朋友可以參考下2014-08-08
C#將html table 導(dǎo)出成excel實(shí)例
C#將html table 導(dǎo)出成excel實(shí)例,需要的朋友可以參考一下2013-04-04

