Table of Contents

Class PrefixUnit

Namespace
Codebelt.Unitify
Assembly
Codebelt.Unitify.dll

Represents the prefix of a unit of measurement.

Examples

Represent a unit of measurement with an associated prefix. This example demonstrates creating PrefixUnit instances with different combinations of base units and prefixes, shows how to construct one from an existing unit, and demonstrates that the prefix parameter is optional (a unit with no prefix has the default None prefix):

using System;
using Codebelt.Unitify;

namespace Unitify.Samples;

public class PrefixUnitExample
{
    public static void Main()
    {
        // Create a kilometer (meter with kilo prefix)
        var kilometer = new PrefixUnit(Unit.Meter, 1.0, DecimalPrefix.Kilo);
        Console.WriteLine($"Distance: {kilometer}");
        
        // Create from an existing unit
        var wattUnit = UnitFactory.CreateWatt(500);
        var kilowatt = new PrefixUnit(wattUnit, DecimalPrefix.Kilo);
        Console.WriteLine($"Power: {kilowatt}");
        
        // Create a megahertz
        var megahertz = new PrefixUnit(Unit.Hertz, 100.0, DecimalPrefix.Mega);
        Console.WriteLine($"Frequency: {megahertz}");
        
        // Prefix can be None (no prefix applied)
        var baseWatt = new PrefixUnit(Unit.Watt, 2500.0);
        Console.WriteLine($"No prefix: {baseWatt}");
    }
}
public class PrefixUnit : Unit, IEquatable<IUnit>, IPrefixUnit, IUnit, IBaseUnit
Inheritance
PrefixUnit
Implements
Inherited Members
Extension Methods

Constructors

PrefixUnit(IBaseUnit, double, IPrefix, Action<UnitFormatOptions>)

Initializes a new instance of the PrefixUnit class.

public PrefixUnit(IBaseUnit baseUnit, double value, IPrefix prefix = null, Action<UnitFormatOptions> setup = null)

Parameters

baseUnit IBaseUnit

The base unit of measurement.

value double

The value of this unit.

prefix IPrefix

The optional prefix to associate with this unit.

setup Action<UnitFormatOptions>

The UnitFormatOptions which may be configured.

PrefixUnit(IUnit, IPrefix)

Initializes a new instance of the PrefixUnit class.

public PrefixUnit(IUnit unit, IPrefix prefix = null)

Parameters

unit IUnit

The unit of measure to shallow copy to this instance.

prefix IPrefix

The prefix to associate with this instance.

Properties

Prefix

Gets the prefix multiple to this unit.

public IPrefix Prefix { get; }

Property Value

IPrefix

The prefix multiple to this unit.

Methods

ToString()

Returns a string that represents this instance.

public override string ToString()

Returns

string

A string that represents this instance.

See Also