扩展方法

using System;

namespace ExtMethod
{
public static class Tool
{
public static void sayHello(this string s)
{
Console.WriteLine(
"Hello " + s + "!");
}
}
}

  将以上代码编译为.dll文件,包含到以下项目中:

using System;
using ExtMethod;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string name = "Kakeru";
name.sayHello();
Console.ReadLine();
}
}
}

  

posted @ 2011-09-16 17:15  绯色卡卡  阅读(113)  评论(0)    收藏  举报