4

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

Jon Seigel
  • 12,251
  • 8
  • 58
  • 92
Christoph
  • 1,964
  • 2
  • 27
  • 44

4 Answers4

5

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

driis
  • 161,458
  • 45
  • 265
  • 341
5

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
  • 7,309
  • 3
  • 50
  • 91
  • 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 Oct 06 '09 at 20:01
1

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
  • 74,184
  • 40
  • 190
  • 334
0

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

user10635
  • 702
  • 4
  • 9