首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

委托的一个例子,运行结果?解决办法

2012-06-05 
委托的一个例子,运行结果?using Systemusing System.Collections.Genericusing System.Linqusing Syste

委托的一个例子,运行结果?
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());

热点排行