本文介绍了在非静态类不是静态方法为什么是一个扩展方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
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:
我们决定这将是对程序员和编译器更加容易,如果我们限制的地方,你必须寻找扩展方法的数量。
这政策往往迫使用户把他们所有的扩展方法进入被指定用于此目的的几个具体类别。
This policy tends to force users to put all of their extension methods into a few specific classes that are designated for this purpose.
这篇关于在非静态类不是静态方法为什么是一个扩展方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!