扩展方法
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();
}
}
}

浙公网安备 33010602011771号