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;
        }
    }
  • 相关阅读:
    test
    在linux下安装tesseract-ocr
    xpath获取同级节点
    RobotFrameWork系统关键字之断言
    redis
    mybatis
    mysql事务隔离级别
    努力努力再努力
    不同分辨率下,页面如何自适应?
    市场上有多少种分辨率?
  • 原文地址:https://www.cnblogs.com/mxw09/p/1790475.html
Copyright © 2011-2022 走看看