• C#模仿JS闭包


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.IO;

    namespace Test
    {
        delegate void MyDelegate();
        delegate MyClosure Closure();
        class Program
        {
            static void Main(string[] args)
            {
                Closure clo = new Closure(Fun);
                MyClosure mm = clo();
                mm.Show();
                mm.Add();
                mm.Show();
                mm.Add();
                mm.Show();
            }

            static MyClosure Fun()
            {
                int num = 2;
                MyClosure myClosure = new MyClosure();
                myClosure.Add = () => { num++; };
                myClosure.Show = () => { Console.WriteLine(num); };
                return myClosure;


            }
        }

        class MyClosure
        {
            public MyDelegate Add;
            public MyDelegate Show;
        }
    }
  • 相关阅读:
    虚拟机下linux系统安装spark一个小提示
    寒假学习记录第七天
    寒假学习记录第六天
    寒假学习记录第五天
    快捷键
    yum安装软件内容
    常见问题处理
    linux目录详解
    linux三剑客
    linux符号与正则表达式
  • 原文地址:https://www.cnblogs.com/mxw09/p/1790475.html
Copyright © 2020-2023  润新知