Has C#/.NET builtin conversion routines for length units?

北城以北 提交于 2019-12-23 12:26:49

问题


Has C#/the .NET library builtin routines or constants for converting e. g. millimetres to inches? If so, where can I find them? (I just do not want to produce duplicate code again and again.)


回答1:


No, there are no such build in routines or constants in the framework.




回答2:


Totally gratuiitous off topic reply

F# has built in support for units. This is a random blog I just Binged Units Of Measure In F#




回答3:


Here's a CodeProject sample that does unit conversion:

http://www.codeproject.com/KB/cs/Thunder.aspx

It's not built-in to .Net, but it will save you from having to write all this stuff yourself.

Update: it makes a bit of sense that this would not be part of .Net, because there are issues regarding the degree of precision to use in the conversions and the constants which are probably best left to the developer.




回答4:


just roll your own set of assemblies which contain the functions so that you don't have to duplicate the code. a simple google search will yield the common conversion formulas. here's a good page.

edited to add the second link...



来源:https://stackoverflow.com/questions/1527682/has-c-net-builtin-conversion-routines-for-length-units

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!