在非静态类不是静态方法为什么是一个扩展方法? [英] Why can't static method in non-static class be an extension method?
问题描述
可能重复:
<一href="http://stackoverflow.com/questions/2731695/extension-method-requires-class-to-be-static">extension方法需要类是静态
在.NET中:
为什么不能静态方法在非静态类是一个扩展方法?
Why can't static method in non-static class be an extension method?
推荐答案
埃里克利珀可能会权衡与这一个一个很好的答案,但它的要点可能会是:
Eric Lippert will probably weigh in with a really good answer on this one, but the gist of it will probably be:
我们决定这将是对程序员和编译器更加容易,如果我们限制的地方,你必须寻找扩展方法的数量。
We decided it would be easier on both programmers and the compiler if we limit the number of places that you have to look for extension methods.
这政策往往迫使用户把他们所有的扩展方法进入被指定用于此目的的几个具体类别。
This policy tends to force users to put all of their extension methods into a few specific classes that are designated for this purpose.
这篇关于在非静态类不是静态方法为什么是一个扩展方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!