Struct MemorySize
- Namespace
- LfrlAnvil.Diagnostics
- Assembly
- LfrlAnvil.Core.dll
Represents a size in memory.
public readonly struct MemorySize : IEquatable<MemorySize>, IComparable<MemorySize>, IComparable
- Implements
- Inherited Members
- Extension Methods
Constructors
MemorySize(long)
Creates a new MemorySize instance.
public MemorySize(long bytes)
Parameters
byteslongTotal amount of bytes.
Fields
BytesPerGigabyte
Constant that defines how many bytes are in a single gigabyte (GB).
public const long BytesPerGigabyte = 1073741824
Field Value
BytesPerKilobyte
Constant that defines how many bytes are in a single kilobyte (KB).
public const long BytesPerKilobyte = 1024
Field Value
BytesPerMegabyte
Constant that defines how many bytes are in a single megabyte (MB).
public const long BytesPerMegabyte = 1048576
Field Value
BytesPerTerabyte
Constant that defines how many bytes are in a single terabyte (TB).
public const long BytesPerTerabyte = 1099511627776
Field Value
Zero
Represents 0 bytes.
public static readonly MemorySize Zero
Field Value
Properties
Bytes
Total amount of bytes.
public long Bytes { get; }
Property Value
BytesInGigabyte
Amount of bytes left after subtraction of FullGigabytes.
public int BytesInGigabyte { get; }
Property Value
BytesInKilobyte
Amount of bytes left after subtraction of FullKilobytes.
public int BytesInKilobyte { get; }
Property Value
BytesInMegabyte
Amount of bytes left after subtraction of FullMegabytes.
public int BytesInMegabyte { get; }
Property Value
BytesInTerabyte
Amount of bytes left after subtraction of FullTerabytes.
public long BytesInTerabyte { get; }
Property Value
FullGigabytes
Total amount of full gigabytes (GB).
public long FullGigabytes { get; }
Property Value
FullKilobytes
Total amount of full kilobytes (KB).
public long FullKilobytes { get; }
Property Value
FullMegabytes
Total amount of full megabytes (MB).
public long FullMegabytes { get; }
Property Value
FullTerabytes
Total amount of full terabytes (TB).
public int FullTerabytes { get; }
Property Value
TotalGigabytes
Total amount of gigabytes (GB).
public double TotalGigabytes { get; }
Property Value
TotalKilobytes
Total amount of kilobytes (KB).
public double TotalKilobytes { get; }
Property Value
TotalMegabytes
Total amount of megabytes (MB).
public double TotalMegabytes { get; }
Property Value
TotalTerabytes
Total amount of terabytes (TB).
public double TotalTerabytes { get; }
Property Value
Methods
Add(MemorySize)
Create a new MemorySize instance by adding other to this instance.
[Pure]
public MemorySize Add(MemorySize other)
Parameters
otherMemorySizeOther instance to add.
Returns
- MemorySize
New MemorySize instance.
CompareTo(MemorySize)
Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.
[Pure]
public int CompareTo(MemorySize other)
Parameters
otherMemorySizeAn object to compare with this instance.
Returns
- int
A value that indicates the relative order of the objects being compared. The return value has these meanings:
Value Meaning Less than zero This instance precedes otherin the sort order.Zero This instance occurs in the same position in the sort order as other.Greater than zero This instance follows otherin the sort order.
CompareTo(object?)
Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.
[Pure]
public int CompareTo(object? obj)
Parameters
objobjectAn object to compare with this instance.
Returns
- int
A value that indicates the relative order of the objects being compared. The return value has these meanings:
Value Meaning Less than zero This instance precedes objin the sort order.Zero This instance occurs in the same position in the sort order as obj.Greater than zero This instance follows objin the sort order.
Exceptions
- ArgumentException
objis not the same type as this instance.
Equals(MemorySize)
Indicates whether the current object is equal to another object of the same type.
[Pure]
public bool Equals(MemorySize other)
Parameters
otherMemorySizeAn object to compare with this object.
Returns
Equals(object?)
Indicates whether this instance and a specified object are equal.
[Pure]
public override bool Equals(object? obj)
Parameters
objobjectThe object to compare with the current instance.
Returns
- bool
true if
objand this instance are the same type and represent the same value; otherwise, false.
FromBytes(double)
Creates a new MemorySize from total amount of bytes.
[Pure]
public static MemorySize FromBytes(double value)
Parameters
valuedoubleTotal amount of bytes.
Returns
- MemorySize
New MemorySize instance.
Remarks
Uses AwayFromZero rounding.
FromBytes(long)
Creates a new MemorySize from total amount of bytes.
[Pure]
public static MemorySize FromBytes(long value)
Parameters
valuelongTotal amount of bytes.
Returns
- MemorySize
New MemorySize instance.
FromGigabytes(double)
Creates a new MemorySize from total amount of gigabytes (GB).
[Pure]
public static MemorySize FromGigabytes(double value)
Parameters
valuedoubleTotal amount of gigabytes.
Returns
- MemorySize
New MemorySize instance.
Remarks
Uses AwayFromZero rounding.
FromGigabytes(long)
Creates a new MemorySize from total amount of gigabytes (GB).
[Pure]
public static MemorySize FromGigabytes(long value)
Parameters
valuelongTotal amount of gigabytes.
Returns
- MemorySize
New MemorySize instance.
FromKilobytes(double)
Creates a new MemorySize from total amount of kilobytes (KB).
[Pure]
public static MemorySize FromKilobytes(double value)
Parameters
valuedoubleTotal amount of kilobytes.
Returns
- MemorySize
New MemorySize instance.
Remarks
Uses AwayFromZero rounding.
FromKilobytes(long)
Creates a new MemorySize from total amount of kilobytes (KB).
[Pure]
public static MemorySize FromKilobytes(long value)
Parameters
valuelongTotal amount of kilobytes.
Returns
- MemorySize
New MemorySize instance.
FromMegabytes(double)
Creates a new MemorySize from total amount of megabytes (MB).
[Pure]
public static MemorySize FromMegabytes(double value)
Parameters
valuedoubleTotal amount of megabytes.
Returns
- MemorySize
New MemorySize instance.
Remarks
Uses AwayFromZero rounding.
FromMegabytes(long)
Creates a new MemorySize from total amount of megabytes (MB).
[Pure]
public static MemorySize FromMegabytes(long value)
Parameters
valuelongTotal amount of megabytes.
Returns
- MemorySize
New MemorySize instance.
FromTerabytes(double)
Creates a new MemorySize from total amount of terabytes (TB).
[Pure]
public static MemorySize FromTerabytes(double value)
Parameters
valuedoubleTotal amount of terabytes.
Returns
- MemorySize
New MemorySize instance.
Remarks
Uses AwayFromZero rounding.
FromTerabytes(long)
Creates a new MemorySize from total amount of terabytes (TB).
[Pure]
public static MemorySize FromTerabytes(long value)
Parameters
valuelongTotal amount of terabytes.
Returns
- MemorySize
New MemorySize instance.
GetHashCode()
Returns the hash code for this instance.
[Pure]
public override int GetHashCode()
Returns
- int
A 32-bit signed integer that is the hash code for this instance.
Subtract(MemorySize)
Create a new MemorySize instance by subtracting other from this instance.
[Pure]
public MemorySize Subtract(MemorySize other)
Parameters
otherMemorySizeOther instance to subtract.
Returns
- MemorySize
New MemorySize instance.
ToString()
Returns a string representation of this MemorySize instance.
[Pure]
public override string ToString()
Returns
- string
String representation.
Operators
operator +(MemorySize, MemorySize)
Creates a new MemorySize instance by adding a and b together.
[Pure]
public static MemorySize operator +(MemorySize a, MemorySize b)
Parameters
aMemorySizeFirst operand.
bMemorySizeSecond operand.
Returns
- MemorySize
New MemorySize instance.
operator ==(MemorySize, MemorySize)
Checks if a is equal to b.
[Pure]
public static bool operator ==(MemorySize a, MemorySize b)
Parameters
aMemorySizeFirst operand.
bMemorySizeSecond operand.
Returns
- bool
true when operands are equal, otherwise false.
operator >(MemorySize, MemorySize)
Checks if a is greater than b.
[Pure]
public static bool operator >(MemorySize a, MemorySize b)
Parameters
aMemorySizeFirst operand.
bMemorySizeSecond operand.
Returns
- bool
true when
ais greater thanb, otherwise false.
operator >=(MemorySize, MemorySize)
Checks if a is greater than or equal to b.
[Pure]
public static bool operator >=(MemorySize a, MemorySize b)
Parameters
aMemorySizeFirst operand.
bMemorySizeSecond operand.
Returns
- bool
true when
ais greater than or equal tob, otherwise false.
operator !=(MemorySize, MemorySize)
Checks if a is not equal to b.
[Pure]
public static bool operator !=(MemorySize a, MemorySize b)
Parameters
aMemorySizeFirst operand.
bMemorySizeSecond operand.
Returns
- bool
true when operands are not equal, otherwise false.
operator <(MemorySize, MemorySize)
Checks if a is less than b.
[Pure]
public static bool operator <(MemorySize a, MemorySize b)
Parameters
aMemorySizeFirst operand.
bMemorySizeSecond operand.
Returns
- bool
true when
ais less thanb, otherwise false.
operator <=(MemorySize, MemorySize)
Checks if a is less than or equal to b.
[Pure]
public static bool operator <=(MemorySize a, MemorySize b)
Parameters
aMemorySizeFirst operand.
bMemorySizeSecond operand.
Returns
- bool
true when
ais less than or equal tob, otherwise false.
operator -(MemorySize, MemorySize)
Creates a new MemorySize instance by subtracting b from a.
[Pure]
public static MemorySize operator -(MemorySize a, MemorySize b)
Parameters
aMemorySizeFirst operand.
bMemorySizeSecond operand.
Returns
- MemorySize
New MemorySize instance.