类型的扩展方法

Kar*_*ten 2 c# extension-methods c#-3.0

有没有办法为类型创建扩展方法?我似乎只能为实例创建它们.

public static class MyExtensions
{
    public static string Test(this string s)
    {
        return "test";
    }
}

public class Test
{
    static void TestIt()
    {
        string.Test();  // won't compile

        string s = null;
        s.Test();
    }
}
Run Code Online (Sandbox Code Playgroud)

Tho*_*que 5

不,这是不可能的.只能为实例创建扩展方法