为什么不支持C#静态类扩展方法

为什么不支持C#静态类扩展方法

本文介绍了为什么不支持C#静态类扩展方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从this问题是扩展方法只能在类实例上运行,而不是静态的类本身。这意味着我不能延长等有用静态类转换数学

我想知道的是,为什么是这样?从上面的链接,对于如何在C#团队可能已经实现了这种功能提出了一些建议。有一些哲学理由不支持它?

例如,这里有一个的理由背后为什么没有内置的LINQ 的ForEach< T> 延长的IEnumerable< T>


解决方案

There's no technical reason, and no philosophical reason. However, as I often point out, I don't have to provide a justification for not doing a feature. Features aren't cheap; they are extremely expensive and they must not only justify their own cost, they must justify the opportunity cost of not doing the hundred other features we could have done with that budget. We must justify the cost of features to our stakeholders, but we need not justify saving time and effort by not implementing features that don't meet our bar.

In particular, the proposed feature does nothing for LINQ; extension methods were added to make LINQ work. Anything that didn't make LINQ work was very hard to get into C# 3.0; we had a lot of work on the schedule and not much time to do it in. (I was surprised that automatic properties made it in.) Cutting an unnecessary feature before even designing it saved a lot of time and effort that was spent on other things that do make LINQ work.

In short: the suggested feature has never met our bar for net benefit over cost, and we've always had more important features to spend our limited time and effort on.

这篇关于为什么不支持C#静态类扩展方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 07:33