Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Working with Units and Amounts

, 17 Jul 2013
The ultimate Unit and Amount classes for your business and physics applications!
using System;
using StandardUnits;
using TypedUnits;

namespace SampleConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            // Just a sample case:
            // ===================

            // To allow using units by name, we'll register all units declared in the "StandardUnits" assembly:
            UnitManager.RegisterByAssembly(typeof(StandardUnits.SIUnitTypes).Assembly);

            // I'm driving in a car driving at 70 Miles per hour:
            var carSpeed = new Amount(70.0, SpeedUnits.MilePerHour);

            // I throw an apple forward through the window at 4 meter per second:
            var relativeAppleSpeed = new Amount(4.0, "meter/second");

            // So the absolute speed of the apple flowing through the air:
            var absoluteAppleSpeed = carSpeed + relativeAppleSpeed;

            // Display the result in km/h:
            Console.WriteLine("Absolute speed of the apple: {0:#,##0.00 US|kilometer/hour}", absoluteAppleSpeed);

            Console.WriteLine();
            Console.WriteLine("Press ENTER to end.");
            Console.ReadLine();
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Rudi Breedenraedt
Architect Wolters Kluwer Belgium
Belgium Belgium
Rudi is a Software Architect at Wolters Kluwer Belgium.

| Advertise | Privacy | Mobile
Web04 | 2.8.140827.1 | Last Updated 17 Jul 2013
Article Copyright 2013 by Rudi Breedenraedt
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid