佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 1318|回复: 0

DOT NET 也有"CODE BLOCK"

[复制链接]
发表于 24-6-2009 11:44 PM | 显示全部楼层 |阅读模式
用过CLIPPER 的人材, 都知道CODE BLOCK 的厉害. DOT NET 也有"CODE BLOCK" 的味道,利用DELEGATE来实现. 下面就是一个简单的例子.

using System;
using System.Collections.Generic;
using System.Text;


namespace ConsoleApplication1
{
    class Program
    {
        public delegate void Dosomething(int i);  //declare code block signature

        static void Main(string[] args)
        {
            List<Dosomething> tasks = new List<Dosomething>();

            tasks.Add(DoactualThing1);
            tasks.Add(DoactualThing2);

            DoActualThing(new Dosomething(DoactualThing1));
            DoActualThing(new Dosomething(DoactualThing2));
            tasks.ForEach(DoActualThing);
            tasks.ForEach(delegate(Dosomething task)
                {
                    task.Invoke(1);
                }
            );
        }
        private static void DoActualThing(Dosomething task)
        {
            task.Invoke(1); //execute the code block
        }

      //concreate code 1
        private static void DoactualThing1(int i)
        {
            Console.WriteLine("Hi folk...i doing first thing....");
        }

      //concreate code 2
        private static void DoactualThing2(int i)
        {
            Console.WriteLine("Hi folk...i doing seconnd thing....");
        }
    }
}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 8-12-2025 02:36 AM , Processed in 0.351756 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表