Class DataPrefixTable
Represents a table of both binary and metric prefixes for units of measure, optimized for data quantity and transmission measurement standards.
Examples
Browse all binary prefix representations of a data storage unit. This example creates a DataPrefixTable from a byte quantity, then displays both the full table of all binary-scaled representations and an aggregate summary showing which scales are available for that unit value:
using System;
using Codebelt.Unitify;
namespace Unitify.Samples;
public class DataPrefixTableExample
{
public static void Main()
{
// Create a unit representing 1,048,576 bytes (1 MiB)
var byteUnit = UnitFactory.CreateByte(1048576);
// Create a data prefix table to see all binary scales
var table = new DataPrefixTable(byteUnit);
// Display all representations
Console.WriteLine("Data storage representations:");
Console.WriteLine(table.ToString());
// Show aggregate summary
Console.WriteLine("\nAggregate:");
Console.WriteLine(table.ToAggregateString());
}
}
public class DataPrefixTable : PrefixTable, IEquatable<IUnit>, IEnumerable<IPrefixUnit>, IEnumerable
- Inheritance
-
DataPrefixTable
- Implements
- Inherited Members
- Extension Methods
Constructors
DataPrefixTable(IUnit)
Initializes a new instance of the DataPrefixTable class.
public DataPrefixTable(IUnit unit)
Parameters
Exceptions
- ArgumentNullException
unitcannot be null.
Fields
DefaultNumberFormat
The default number format used for displaying values related to DataPrefixTable.
public const string DefaultNumberFormat = "#,##0.##"
Field Value
Methods
CreateBitTableFromBits(double, Action<UnitFormatOptions>)
Creates a new instance of DataPrefixTable initialized with value.
public static DataPrefixTable CreateBitTableFromBits(double value, Action<UnitFormatOptions> setup = null)
Parameters
valuedoubleThe double to convert.
setupAction<UnitFormatOptions>The UnitFormatOptions which may be configured.
Returns
- DataPrefixTable
A DataPrefixTable that is equivalent to
valuewith a base unit of Bit.
CreateBitTableFromBytes(double, Action<UnitFormatOptions>)
Creates a new instance of DataPrefixTable initialized with value.
public static DataPrefixTable CreateBitTableFromBytes(double value, Action<UnitFormatOptions> setup = null)
Parameters
valuedoubleThe double to convert.
setupAction<UnitFormatOptions>The UnitFormatOptions which may be configured.
Returns
- DataPrefixTable
A DataPrefixTable that is equivalent to
valuewith a base unit of Bit.
CreateByteTableFromBits(double, Action<UnitFormatOptions>)
Creates a new instance of DataPrefixTable initialized with value.
public static DataPrefixTable CreateByteTableFromBits(double value, Action<UnitFormatOptions> setup = null)
Parameters
valuedoubleThe double to convert.
setupAction<UnitFormatOptions>The UnitFormatOptions which may be configured.
Returns
- DataPrefixTable
A DataPrefixTable that is equivalent to
valuewith a base unit of Byte.
CreateByteTableFromBytes(double, Action<UnitFormatOptions>)
Creates a new instance of DataPrefixTable initialized with value.
public static DataPrefixTable CreateByteTableFromBytes(double value, Action<UnitFormatOptions> setup = null)
Parameters
valuedoubleThe double to convert.
setupAction<UnitFormatOptions>The UnitFormatOptions which may be configured.
Returns
- DataPrefixTable
A DataPrefixTable that is equivalent to
valuewith a base unit of Byte.
GetEnumerator()
Returns an enumerator that iterates through the collection of prefixes.
public override IEnumerator<IPrefixUnit> GetEnumerator()
Returns
- IEnumerator<IPrefixUnit>
An enumerator that can be used to iterate through the collection of prefixes.
ToAggregateString(bool, bool, bool)
Returns an aggregated string of all multiple prefixes of this instance.
public string ToAggregateString(bool includeBinary = true, bool includeDecimal = true, bool includeUnit = true)
Parameters
includeBinaryboolIf set to
true, includes all binary-multiple prefixes in the aggregate.includeDecimalboolIf set to
true, includes all metric-multiple prefixes in the aggregate.includeUnitboolIf set to
true, includes the base unit in the aggregate.
Returns
ToString()
Returns a string that represents the largest multiple prefix of this instance.
public override string ToString()
Returns
Remarks
Evaluates the largest multiple prefix that is greater or equal to 1 and returns it formatted as Binary.
ToString(PrefixStyle)
Returns a string that represents the largest multiple prefix of this instance.
public string ToString(PrefixStyle prefixStyle)
Parameters
prefixStylePrefixStyleThe preferred unit prefix style for formatting.
Returns
Remarks
Evaluates the largest metric-multiple prefix that is greater or equal to 1 and returns it formatted as either Binary or Decimal.