Table of Contents

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

bytes long

Total amount of bytes.

Fields

BytesPerGigabyte

Constant that defines how many bytes are in a single gigabyte (GB).

public const long BytesPerGigabyte = 1073741824

Field Value

long

BytesPerKilobyte

Constant that defines how many bytes are in a single kilobyte (KB).

public const long BytesPerKilobyte = 1024

Field Value

long

BytesPerMegabyte

Constant that defines how many bytes are in a single megabyte (MB).

public const long BytesPerMegabyte = 1048576

Field Value

long

BytesPerTerabyte

Constant that defines how many bytes are in a single terabyte (TB).

public const long BytesPerTerabyte = 1099511627776

Field Value

long

Zero

Represents 0 bytes.

public static readonly MemorySize Zero

Field Value

MemorySize

Properties

Bytes

Total amount of bytes.

public long Bytes { get; }

Property Value

long

BytesInGigabyte

Amount of bytes left after subtraction of FullGigabytes.

public int BytesInGigabyte { get; }

Property Value

int

BytesInKilobyte

Amount of bytes left after subtraction of FullKilobytes.

public int BytesInKilobyte { get; }

Property Value

int

BytesInMegabyte

Amount of bytes left after subtraction of FullMegabytes.

public int BytesInMegabyte { get; }

Property Value

int

BytesInTerabyte

Amount of bytes left after subtraction of FullTerabytes.

public long BytesInTerabyte { get; }

Property Value

long

FullGigabytes

Total amount of full gigabytes (GB).

public long FullGigabytes { get; }

Property Value

long

FullKilobytes

Total amount of full kilobytes (KB).

public long FullKilobytes { get; }

Property Value

long

FullMegabytes

Total amount of full megabytes (MB).

public long FullMegabytes { get; }

Property Value

long

FullTerabytes

Total amount of full terabytes (TB).

public int FullTerabytes { get; }

Property Value

int

TotalGigabytes

Total amount of gigabytes (GB).

public double TotalGigabytes { get; }

Property Value

double

TotalKilobytes

Total amount of kilobytes (KB).

public double TotalKilobytes { get; }

Property Value

double

TotalMegabytes

Total amount of megabytes (MB).

public double TotalMegabytes { get; }

Property Value

double

TotalTerabytes

Total amount of terabytes (TB).

public double TotalTerabytes { get; }

Property Value

double

Methods

Add(MemorySize)

Create a new MemorySize instance by adding other to this instance.

[Pure]
public MemorySize Add(MemorySize other)

Parameters

other MemorySize

Other 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

other MemorySize

An 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 other in the sort order.
Zero This instance occurs in the same position in the sort order as other.
Greater than zero This instance follows other in 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

obj object

An 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 obj in the sort order.
Zero This instance occurs in the same position in the sort order as obj.
Greater than zero This instance follows obj in the sort order.

Exceptions

ArgumentException

obj is 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

other MemorySize

An object to compare with this object.

Returns

bool

true if the current object is equal to the other parameter; otherwise, false.

Equals(object?)

Indicates whether this instance and a specified object are equal.

[Pure]
public override bool Equals(object? obj)

Parameters

obj object

The object to compare with the current instance.

Returns

bool

true if obj and 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

value double

Total 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

value long

Total 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

value double

Total 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

value long

Total 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

value double

Total 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

value long

Total 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

value double

Total 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

value long

Total 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

value double

Total 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

value long

Total 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

other MemorySize

Other 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

a MemorySize

First operand.

b MemorySize

Second 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

a MemorySize

First operand.

b MemorySize

Second 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

a MemorySize

First operand.

b MemorySize

Second operand.

Returns

bool

true when a is greater than b, 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

a MemorySize

First operand.

b MemorySize

Second operand.

Returns

bool

true when a is greater than or equal to b, otherwise false.

operator !=(MemorySize, MemorySize)

Checks if a is not equal to b.

[Pure]
public static bool operator !=(MemorySize a, MemorySize b)

Parameters

a MemorySize

First operand.

b MemorySize

Second 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

a MemorySize

First operand.

b MemorySize

Second operand.

Returns

bool

true when a is less than b, 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

a MemorySize

First operand.

b MemorySize

Second operand.

Returns

bool

true when a is less than or equal to b, 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

a MemorySize

First operand.

b MemorySize

Second operand.

Returns

MemorySize

New MemorySize instance.