问题
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