代码改变世界

C#中的委托例子,备查

2008-05-10 12:26  OntheMars  阅读(169)  评论(0)    收藏  举报
using System;
using System.Collections.Generic;
using System.Text;

namespace delegateExp1
{
    
class Program
    
{
        
delegate void SimpleDelegate();

        
static void F()
        
{
            System.Console.WriteLine(
"hello world");
        }


        
static void MultiCall(SimpleDelegate d, int count)
        
{
            
for (int i = 0; i < count; i++)
                d();
        }


     


        
static void Main(string[] args)
        
{
            
//SimpleDelegate d = new SimpleDelegate(F);//将方法压入 
            
//d();//委托调用
            
//F();//
      
       

        }


    }

}


   
上面的例子简单说明了委托的用法,其实就是实现了函数指针的用处。