Skip to main content
Version: 4.0 (next)

Humanizer.ByteRate

ByteRate Class​

Class to hold a ByteSize and a measurement interval, for the purpose of calculating the rate of transfer

public class ByteRate : System.IComparable<Humanizer.ByteRate>, System.IEquatable<Humanizer.ByteRate>, System.IComparable

Inheritance System.Object → ByteRate

Implements System.IComparable<ByteRate>, System.IEquatable<ByteRate>, System.IComparable

Remarks​

Create a ByteRate with given quantity of bytes across an interval

Constructors​

ByteRate(ByteSize, TimeSpan) Constructor​

Class to hold a ByteSize and a measurement interval, for the purpose of calculating the rate of transfer

public ByteRate(Humanizer.ByteSize size, System.TimeSpan interval);
Parameters​

size ByteSize

interval System.TimeSpan

Remarks​

Create a ByteRate with given quantity of bytes across an interval

Properties​

ByteRate.Interval Property​

Interval that bytes were transferred in

public System.TimeSpan Interval { get; }
Property Value​

System.TimeSpan

ByteRate.Size Property​

Quantity of bytes

public Humanizer.ByteSize Size { get; }
Property Value​

ByteSize

Methods​

ByteRate.CompareTo(ByteRate) Method​

Compares this rate with another rate after normalizing both to bytes per second.

public int CompareTo(Humanizer.ByteRate? other);
Parameters​

other ByteRate

The rate to compare with.

Returns​

System.Int32

ByteRate.CompareTo(object) Method​

Compares this rate with another object.

public int CompareTo(object? obj);
Parameters​

obj System.Object

The rate to compare with this instance, or null.

Implements CompareTo(object)

Returns​

System.Int32
A value less than zero if this instance precedes obj in the sort order; zero if they have the same position; or greater than zero if this instance follows obj or obj is null.

Exceptions​

System.ArgumentException
obj is not a ByteRate.

ByteRate.Equals(ByteRate) Method​

public bool Equals(Humanizer.ByteRate? other);
Parameters​

other ByteRate

Returns​

System.Boolean

ByteRate.Equals(object) Method​

Determines whether the specified object is equal to the current object.

public override bool Equals(object? obj);
Parameters​

obj System.Object

The object to compare with the current object.

Returns​

System.Boolean
true if the specified object is equal to the current object; otherwise, false.

ByteRate.GetHashCode() Method​

Serves as the default hash function.

public override int GetHashCode();
Returns​

System.Int32
A hash code for the current object.

ByteRate.Humanize(TimeUnit) Method​

Calculate rate for the quantity of bytes and interval defined by this instance

public string Humanize(Humanizer.TimeUnit timeUnit=Humanizer.TimeUnit.Second);
Parameters​

timeUnit TimeUnit

Unit of time to calculate rate for (defaults is per second)

Returns​

System.String

ByteRate.Humanize(string, TimeUnit, CultureInfo) Method​

Calculate rate for the quantity of bytes and interval defined by this instance

public string Humanize(string? format, Humanizer.TimeUnit timeUnit=Humanizer.TimeUnit.Second, System.Globalization.CultureInfo? culture=null);
Parameters​

format System.String

The string format to use for the number of bytes

timeUnit TimeUnit

Unit of time to calculate rate for (defaults is per second)

culture System.Globalization.CultureInfo

Culture to use. If null, current thread's culture is used.

Returns​

System.String

ByteRate.HumanizeWithUnitSystem(ByteSizeUnitSystem, string, TimeUnit, CultureInfo) Method​

Calculates and humanizes this rate using an explicitly selected byte-size unit system.

public string HumanizeWithUnitSystem(Humanizer.ByteSizeUnitSystem unitSystem, string? format=null, Humanizer.TimeUnit timeUnit=Humanizer.TimeUnit.Second, System.Globalization.CultureInfo? culture=null);
Parameters​

unitSystem ByteSizeUnitSystem

The byte-size unit system to use.

format System.String

The numeric format and optional byte-size unit token. For DecimalSi and BinaryIec, SI/IEC-prefixed unit tokens are matched case-insensitively, while b and B remain case-sensitive; output uses canonical symbol casing. Legacy preserves established matching behavior.

timeUnit TimeUnit

The time unit to use for the displayed rate.

culture System.Globalization.CultureInfo

The culture used to format the numeric value, byte-size unit, and time-unit symbol.

Returns​

System.String
The humanized rate.

Exceptions​

System.ArgumentOutOfRangeException
unitSystem is not defined.

System.NotSupportedException
timeUnit is not Second, Minute, or Hour.

System.FormatException
format is invalid, or selects a token not supported by the selected non-legacy system.

ByteRate.ToString() Method​

Returns the humanized rate using the default format and time unit.

public override string ToString();
Returns​

System.String