c# Func委托 深入c# Func委托的详解

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

c# Func委托 深入c# Func委托的详解

  2021-03-18 我要评论
想了解深入c# Func委托的详解的相关内容吗,在本文为您仔细讲解c# Func委托的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:c#,Func委托,下面大家一起来学习吧。
如下所示:
复制代码 代码如下:

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();
        }
    }
}

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们