views:

331

answers:

5

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.)

+4  A: 

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

driis
+1  A: 

Can you use someone else's?

Thunder Measurement Unit Conversion Framework

Jay Riggs
That's the third time this has happened to me today, where somebody beats me to the exact same link by a couple of seconds. +1 for your superior Google-fu.
MusiGenesis
Ha! I wasn't sure if you beat me! +1 for great minds think alike.
Jay Riggs
You beat me like a drum.
MusiGenesis
+1  A: 

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.

MusiGenesis
A: 

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...

+1  A: 

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#

Peter M
I don't think that's gratuitious or off topic, *if* you can use that DLL from a C# application. I would guess it's possible, since you can reference Microsoft.VisualBasic from a C# app.
MusiGenesis