本文介绍了类型扩展方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以为类型创建扩展方法?我似乎只能为实例创建它们.
Is there a way to create an extension method for an type ? I only seem to be able to create them for instances.
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(); } } 推荐答案否,这是不可能的.扩展方法只能为实例创建
No, it's not possible. Extension methods can only be created for instances
更多推荐
类型扩展方法
发布评论