日期:2014-05-18  浏览次数:20765 次

委托的一个例子,运行结果?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication24
{
  public delegate string MyString();
  public class Program
  {
  static void Main(string[] args)
  {
  int x = 40;
  MyString Ms = new MyString(x.ToString);
  Console.WriteLine("输出的字符"+Ms);
  }
  }
}
书上的结果是:输出的字符40
为什么我运行的结果不是这样的呢?

------解决方案--------------------
你的MyString 呢?
------解决方案--------------------
Console.WriteLine("输出的字符" + Ms());
不加 () ,输出的类型名,加了 () ,让它执行,才能输出结果
------解决方案--------------------
Console.WriteLine("输出的字符" + Ms);
===>
Console.WriteLine("输出的字符" + Ms());