LmT*_*oon 7 c# language-design
我探索了c#源代码参考.我偶然发现有趣的IArithmetic<T>
界面.例如,Int32
,Double
包含评论的实现IArithmetic
接口.我对这些细节很感兴趣.据我所知,它试图添加"支持"算术运算.但为什么他们评论?是否添加支持通用"运营商"的方法不好?
它可能由于性能原因而被废弃,而且可用性不高。
通过接口支持算术运算的原始类型确实不是一个很有吸引力的场景;由于必要的装箱和拆箱,与简单地使用值类型本身相比,性能会很糟糕。
有哪些可能的用途?好吧,第一个想到的是以下场景:
public Matrix<T> where T: IArithmetic<T>
Run Code Online (Sandbox Code Playgroud)
or some such. Although this could be interesting, due to performance reasons, it would probably need to be solved some other way, not through interfaces; read this for very educated musing on the subject.
On top of all that, if you really need something similar to Arithmetic<T>
you can always build your own with an added level of indirection.
归档时间: |
|
查看次数: |
694 次 |
最近记录: |