Popular Posts
DataList paging //利用PageDataSource來做分頁功能 PagedDataSource pds = new PagedDataSource(); //將PageDataSource綁定SqlDataSource pds.DataSource = SqlDataSource1.Selec... 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.... Build an OpenVPN server on android device Preparation An android device, in this case, Sony xperia Z is used Root permission required Linux Deploy for deploy i...
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);
            }
        }
    }

}