zoukankan      html  css  js  c++  java
  • 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;
        }
    }
  • 相关阅读:
    nginx平滑升级及回滚
    redis源码安装
    memcached安装
    Harbor源码部署
    Maven源码部署
    tomcat单机多实例(未完待续)
    部署tomcat
    nginx编译参数详解
    CentOS7 安装pip/pip3
    nginx 部署配置
  • 原文地址:https://www.cnblogs.com/mxw09/p/1790475.html
Copyright © 2011-2022 走看看