Popular Posts
ListSelectionListener & ItemListener import java.awt.Dimension; import java.awt.FlowLayout; import java.awt.Toolkit; import java.awt.event.ItemEvent; import java.awt.event.ItemL... netbean shortcut Ctrl + F:尋找 F3:尋找下一個字串 Ctrl + G:跳到第 N 行 Ctrl + H:取代 Tab:增加縮排 Shift + Tab:減少縮排 Ctrl + E:刪除一行 Ctrl + Shift + I:修正 import 項目 Alt + Ent... Capture response output stream using HttpModule using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Web; namespace TestWebA...
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);
            }
        }
    }

}