Popular Posts
Enable edit option in Shutter in Linux sudo apt-get install libgoo-canvas-perl Reference: How To Fix Disabled Edit Option In Shutter in Linux Mint CORS in Asp.net MVC Web API v2 Step 1. Install cors from NeGet Step 2. Enable cors in config using System; using System.Collections.Generic; using System.Linq; using ... DNS SERVER LIST Google 8.8.8.8 8.8.4.4 TWNIC 192.83.166.11 211.72.210.250 HiNet 168.95.1.1 168.95.192.1 Seednet 北區 DNS (台北, 桃園, 新竹, 宜蘭, 花蓮, 苗栗) 139....
Stats
review : delegate in c#
I think I've got old because while using delegate, I couldn't remember it's usage. So I think it's a good idea to take a review and memo it here.
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Linq;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;

namespace wfConsole
{
    delegate void PrintLine();
    delegate void PrintContent(string s, int count);

    public sealed partial class Workflow1 : SequentialWorkflowActivity
    {
        public Workflow1()
        {
            InitializeComponent();
        }

        private void ReviewDelegate_ExecuteCode(object sender, EventArgs e)
        {
            // 委派 C# 1.0
            PrintLine pl = new PrintLine(this.WriteLine);
            PrintContent pc = new PrintContent(this.WriteContent);
            pl.Invoke();
            pc.Invoke("C# 1.0", 5);

            // 委派 C# 2.0
            PrintLine pl2 = delegate()
            {
                Console.WriteLine("********************");
            };
            PrintContent pc2 = delegate(string s, int count)
            {
                for (int i = 0; i < count; i++)
                {
                    Console.Write("{0:00} ", i + 1);
                    Console.WriteLine(s);
                }
            };
            pl2.Invoke();
            pc2.Invoke("C# 2.0", 5);

            // 委派 C# 3.0
            PrintLine pl3 = () =>
            {
                Console.WriteLine("----------------------");
            };
            PrintContent pc3 = (string s, int count) =>
            {
                for (int i = 0; i < count; i++)
                {
                    Console.Write("{0:00} ", i + 1);
                    Console.WriteLine(s);
                }
            };
            pl3.Invoke();
            pc3.Invoke("C# 3.0", 5);

            Console.Read();
        }

        private void WriteLine()
        {
            Console.WriteLine("=========================");
        }

        private void WriteContent(string s, int count)
        {
            for (int i = 0; i < count; i++)
            {
                Console.Write("{0:00} ", i + 1);
                Console.WriteLine(s);
            }
        }
    }

}