C# 匿名方法和拉姆达表达式「建议收藏」

C# 匿名方法和拉姆达表达式「建议收藏」“`“`代码如下:usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;namespace拉姆拉表达式{///

///C#匿名方法和拉姆达表达

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺

“`

“`代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 拉姆拉表达式 
{
/// <summary>
/// C# 匿名方法和拉姆达表达式
/// </summary>
class Program
{
    public delegate void myDel();//【1】
    public delegate void myDelString (string str);//【2】
    public delegate string  myDelReString(string str);//【3】
    public delegate int myDelReInt(int num1,int num2);//【4】
    static void Main(string[] args)
    {
        【1】--------------------------------------------------
        myDel dlg = new myDel(todo);  
        myDel dlgA = todo;

        //匿名函数定义
        myDel dlgB = delegate() { Console.WriteLine("方法B"); };
        //拉姆达
        myDel dlgC = ()=> { Console.WriteLine("方法C"); };
        【1】--------------------------------------------------


        【2】--------------------------------------------------
        myDelString dlgD = s => Console.WriteLine(s);
        dlgD("拉达姆");
        【2】--------------------------------------------------

        【3】--------------------------------------------------
        myDelReString dlgE = s => s + "+拉达姆";
        string str=dlgE("拉达姆");
        Console.WriteLine(str);
        【3】--------------------------------------------------

        【4】--------------------------------------------------
        toAdd((a, b) => a + b);
        【4】--------------------------------------------------


        【SSS】--------------------------------------------------
        List<int> list = new List<int>() { 1, 3, 5, 7, 9 };
        IEnumerable<int> nums= list.Where(w => w > 5);

        foreach (var item in nums)
        {
            Console.WriteLine(item);
        }


        【SSS】--------------------------------------------------

        Console.Read();
    }
    public static void todo()
    {
        Console.WriteLine("方法");
    }
    public static void toAdd(myDelReInt delInt)
    {
        int result = delInt(1,2);
        Console.WriteLine(result);
    }
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/193518.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • pycharm2021.11.2激活码_在线激活「建议收藏」

    (pycharm2021.11.2激活码)好多小伙伴总是说激活码老是失效,太麻烦,关注/收藏全栈君太难教程,2021永久激活的方法等着你。https://javaforall.net/100143.htmlIntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,上面是详细链接哦~9K2BT69C4S-eyJsaWNlbnNlSWQiOi…

    2022年3月28日
    60
  • 简单工厂模式

    简单工厂模式

    2021年12月10日
    50
  • 最长公共子串 动态规划_最长公共子串 DNA序列

    最长公共子串 动态规划_最长公共子串 DNA序列原题链接题目描述给定两个字符串str1和str2,输出连个字符串的最长公共子序列。如过最长公共子序列为空,则输出-1。输入描述:输出包括两行,第一行代表字符串str1,第二行代表str2。( 1<= length(str1),length(str2)<= 5000)输出描述:输出一行,代表他们最长公共子序列。如果公共子序列的长度为空,则输出-1。示例1输入1A2C3D4B56B1D23CA45B6A输出123456说明”123456″和“12C4B6”都是最长公共

    2022年8月8日
    8
  • beanUtils.copy_拷贝板原理

    beanUtils.copy_拷贝板原理本文用实例介绍BeanUtils的拷贝原理。

    2025年8月28日
    4
  • ubuntu20更换国内源_ubuntu更换国内源

    ubuntu20更换国内源_ubuntu更换国内源[Fedora-ftp.sjtu.edu.cn]name=Fedora12-i386baseurl=http://ftp.sjtu.edu.cn/fedora/linux/releases/12/Fedora/i386/os/enabled=1gpgcheck=0gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora[Eve

    2022年9月20日
    3
  • SIMD and Avx2

    SIMD and Avx2SIMD一条指令可以执行多个数据group的计算和输出。对于SIMD相对应的SISD.intel SSE2 ,AVX2,AVX-512假设有一个任务是统计字符串中每一个字符出现的次数,我们可以用128bit的SISD指令进行统计。每8个bit代表一个字符,所以只需要两个SIMD指令(movemask、popcount)。详细测试:#include<stdio.h>#include<thread>#defineINC_TO1000000//o

    2022年5月7日
    31

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号