ByteSize Struct

Represents a byte size value that can be formatted, parsed, and compared. Supports both decimal (kB, MB, GB) and binary (kiB, MiB, GiB) units.

Example

// Create an instance
var size = new ByteSize(1024);
var size2 = ByteSize.FromKiloBytes(10);
var size3 = ByteSize.Parse("10MB", CultureInfo.InvariantCulture);
Assert.Equal(10_000, size2.Value);
Assert.Equal(10_000_000, size3.Value);

// Format with automatic unit selection
Assert.Equal("1.024kB", size.ToString(CultureInfo.InvariantCulture)); // decimal units
Assert.Equal("1kiB", size.ToString("gi", CultureInfo.InvariantCulture)); // binary units

// Format with specific unit
Assert.Equal("0.001024MB", size.ToString("MB", CultureInfo.InvariantCulture));

// Perform arithmetic operations
var total = ByteSize.FromKiloBytes(1) + ByteSize.FromKiloBytes(2);
Assert.Equal("3kB", total.ToString(CultureInfo.InvariantCulture));
Implements

Constructors

NameDescription
ByteSize(long)Initializes a new instance of the ByteSize struct with the specified byte value.

ByteSize(long)

ByteSize.cs

Initializes a new instance of the ByteSize struct with the specified byte value.

public ByteSize(long length)

Parameters

length long
The size in bytes.

Properties

NameDescription
MaxValueGets a ByteSize instance representing the maximum possible byte value.
MinValueGets a ByteSize instance representing the minimum possible byte value.
ValueGets the size in bytes.
ZeroGets a ByteSize instance representing zero bytes.

MaxValue

ByteSize.cs

Gets a ByteSize instance representing the maximum possible byte value.

public static ByteSize MaxValue { get; }

Property value

ByteSize

MinValue

ByteSize.cs

Gets a ByteSize instance representing the minimum possible byte value.

public static ByteSize MinValue { get; }

Property value

ByteSize

Gets the size in bytes.

public long Value { get; }

Property value

long

Gets a ByteSize instance representing zero bytes.

public static ByteSize Zero { get; }

Property value

ByteSize

Methods

NameDescription
Add(ByteSize)Adds two byte size values.
CompareTo(ByteSize)
CompareTo(object?)
Divide(long)Divides this byte size by a factor.
Equals(ByteSize)
Equals(object?)
From(byte, ByteSizeUnit)Creates a ByteSize instance from a value and unit.
From(double, ByteSizeUnit)Creates a ByteSize instance from a value and unit.
From(short, ByteSizeUnit)Creates a ByteSize instance from a value and unit.
From(int, ByteSizeUnit)Creates a ByteSize instance from a value and unit.
From(long, ByteSizeUnit)Creates a ByteSize instance from a value and unit.
From(float, ByteSizeUnit)Creates a ByteSize instance from a value and unit.
FromBytes(byte)Creates a ByteSize instance from a byte value.
FromBytes(double)Creates a ByteSize instance from a byte value.
FromBytes(short)Creates a ByteSize instance from a byte value.
FromBytes(int)Creates a ByteSize instance from a byte value.
FromBytes(long)Creates a ByteSize instance from a byte value.
FromBytes(float)Creates a ByteSize instance from a byte value.
FromExaBytes(byte)Creates a ByteSize instance from a exabyte value.
FromExaBytes(double)Creates a ByteSize instance from a exabyte value.
FromExaBytes(short)Creates a ByteSize instance from a exabyte value.
FromExaBytes(int)Creates a ByteSize instance from a exabyte value.
FromExaBytes(long)Creates a ByteSize instance from a exabyte value.
FromExaBytes(float)Creates a ByteSize instance from a exabyte value.
FromExbiBytes(byte)Creates a ByteSize instance from a exbibyte value.
FromExbiBytes(double)Creates a ByteSize instance from a exbibyte value.
FromExbiBytes(short)Creates a ByteSize instance from a exbibyte value.
FromExbiBytes(int)Creates a ByteSize instance from a exbibyte value.
FromExbiBytes(long)Creates a ByteSize instance from a exbibyte value.
FromExbiBytes(float)Creates a ByteSize instance from a exbibyte value.
FromFileLength(FileInfo)Creates a ByteSize instance from a file's length.
FromFileLength(string)Creates a ByteSize instance from a file's length.
FromGibiBytes(byte)Creates a ByteSize instance from a gibibyte value.
FromGibiBytes(double)Creates a ByteSize instance from a gibibyte value.
FromGibiBytes(short)Creates a ByteSize instance from a gibibyte value.
FromGibiBytes(int)Creates a ByteSize instance from a gibibyte value.
FromGibiBytes(long)Creates a ByteSize instance from a gibibyte value.
FromGibiBytes(float)Creates a ByteSize instance from a gibibyte value.
FromGigaBytes(byte)Creates a ByteSize instance from a gigabyte value.
FromGigaBytes(double)Creates a ByteSize instance from a gigabyte value.
FromGigaBytes(short)Creates a ByteSize instance from a gigabyte value.
FromGigaBytes(int)Creates a ByteSize instance from a gigabyte value.
FromGigaBytes(long)Creates a ByteSize instance from a gigabyte value.
FromGigaBytes(float)Creates a ByteSize instance from a gigabyte value.
FromKibiBytes(byte)Creates a ByteSize instance from a kibibyte value.
FromKibiBytes(double)Creates a ByteSize instance from a kibibyte value.
FromKibiBytes(short)Creates a ByteSize instance from a kibibyte value.
FromKibiBytes(int)Creates a ByteSize instance from a kibibyte value.
FromKibiBytes(long)Creates a ByteSize instance from a kibibyte value.
FromKibiBytes(float)Creates a ByteSize instance from a kibibyte value.
FromKiloBytes(byte)Creates a ByteSize instance from a kilobyte value.
FromKiloBytes(double)Creates a ByteSize instance from a kilobyte value.
FromKiloBytes(short)Creates a ByteSize instance from a kilobyte value.
FromKiloBytes(int)Creates a ByteSize instance from a kilobyte value.
FromKiloBytes(long)Creates a ByteSize instance from a kilobyte value.
FromKiloBytes(float)Creates a ByteSize instance from a kilobyte value.
FromMebiBytes(byte)Creates a ByteSize instance from a mebibyte value.
FromMebiBytes(double)Creates a ByteSize instance from a mebibyte value.
FromMebiBytes(short)Creates a ByteSize instance from a mebibyte value.
FromMebiBytes(int)Creates a ByteSize instance from a mebibyte value.
FromMebiBytes(long)Creates a ByteSize instance from a mebibyte value.
FromMebiBytes(float)Creates a ByteSize instance from a mebibyte value.
FromMegaBytes(byte)Creates a ByteSize instance from a megabyte value.
FromMegaBytes(double)Creates a ByteSize instance from a megabyte value.
FromMegaBytes(short)Creates a ByteSize instance from a megabyte value.
FromMegaBytes(int)Creates a ByteSize instance from a megabyte value.
FromMegaBytes(long)Creates a ByteSize instance from a megabyte value.
FromMegaBytes(float)Creates a ByteSize instance from a megabyte value.
FromPebiBytes(byte)Creates a ByteSize instance from a pebibyte value.
FromPebiBytes(double)Creates a ByteSize instance from a pebibyte value.
FromPebiBytes(short)Creates a ByteSize instance from a pebibyte value.
FromPebiBytes(int)Creates a ByteSize instance from a pebibyte value.
FromPebiBytes(long)Creates a ByteSize instance from a pebibyte value.
FromPebiBytes(float)Creates a ByteSize instance from a pebibyte value.
FromPetaBytes(byte)Creates a ByteSize instance from a petabyte value.
FromPetaBytes(double)Creates a ByteSize instance from a petabyte value.
FromPetaBytes(short)Creates a ByteSize instance from a petabyte value.
FromPetaBytes(int)Creates a ByteSize instance from a petabyte value.
FromPetaBytes(long)Creates a ByteSize instance from a petabyte value.
FromPetaBytes(float)Creates a ByteSize instance from a petabyte value.
FromTebiBytes(byte)Creates a ByteSize instance from a tebibyte value.
FromTebiBytes(double)Creates a ByteSize instance from a tebibyte value.
FromTebiBytes(short)Creates a ByteSize instance from a tebibyte value.
FromTebiBytes(int)Creates a ByteSize instance from a tebibyte value.
FromTebiBytes(long)Creates a ByteSize instance from a tebibyte value.
FromTebiBytes(float)Creates a ByteSize instance from a tebibyte value.
FromTeraBytes(byte)Creates a ByteSize instance from a terabyte value.
FromTeraBytes(double)Creates a ByteSize instance from a terabyte value.
FromTeraBytes(short)Creates a ByteSize instance from a terabyte value.
FromTeraBytes(int)Creates a ByteSize instance from a terabyte value.
FromTeraBytes(long)Creates a ByteSize instance from a terabyte value.
FromTeraBytes(float)Creates a ByteSize instance from a terabyte value.
GetHashCode()
GetValue(ByteSizeUnit)Converts the byte size to the specified unit.
Multiply(long)Scales this byte size by a factor.
Parse(ReadOnlySpan<byte>)Parses a span of UTF-8 characters into a ByteSize value.
Parse(ReadOnlySpan<char>, IFormatProvider?)Parses a span of characters into a ByteSize value.
Parse(string, IFormatProvider?)Converts the string representation of a byte size to its ByteSize equivalent.
Subtract(ByteSize)Subtracts a byte size value from this instance.
ToString()
ToString(ByteSizeUnit)
ToString(ByteSizeUnit, IFormatProvider?)
ToString(IFormatProvider?)
ToString(string?)Convert value to string
ToString(string?, IFormatProvider?)Convert value to string
TryFormat(Span<byte>, int, ReadOnlySpan<char>, IFormatProvider?)Tries to format the value as UTF-8 into the provided span of bytes.
TryFormat(Span<char>, int, ReadOnlySpan<char>, IFormatProvider?)Tries to format the value into the provided span of characters.
TryParse(ReadOnlySpan<byte>, ByteSize)Tries to parse a span of UTF-8 characters into a ByteSize value.
TryParse(ReadOnlySpan<char>, IFormatProvider?, ByteSize)Tries to parse a span of characters into a ByteSize value.
TryParse(string, ByteSize)Tries to convert the string representation of a byte size to its ByteSize equivalent.
TryParse(string?, IFormatProvider?, ByteSize)Tries to convert the string representation of a byte size to its ByteSize equivalent.

Add(ByteSize)

ByteSize.cs

Adds two byte size values.

public ByteSize Add(ByteSize other)

Parameters

other ByteSize
The value to add.

Returns

ByteSize The sum of the two byte sizes.

CompareTo overloads

CompareTo(ByteSize)

ByteSize.cs
public int CompareTo(ByteSize other)
Parameters
other ByteSize
Returns

int

No documentation is available.

CompareTo(object?)

ByteSize.cs
public int CompareTo(object? obj)
Parameters
obj object?
Returns

int

No documentation is available.

Divide(long)

ByteSize.cs

Divides this byte size by a factor.

public ByteSize Divide(long divisor)

Parameters

divisor long
The factor to divide by.

Returns

ByteSize The divided byte size.

Equals overloads

Equals(ByteSize)

ByteSize.cs
public bool Equals(ByteSize other)
Parameters
other ByteSize
Returns

bool

No documentation is available.

Equals(object?)

ByteSize.cs
public override bool Equals(object? obj)
Parameters
obj object?
Returns

bool

No documentation is available.

From overloads

From(byte, ByteSizeUnit)

ByteSize.cs

Creates a ByteSize instance from a value and unit.

public static ByteSize From(byte value, ByteSizeUnit unit)
Parameters
value byte
The numeric value.
unit ByteSizeUnit
The unit of the value.
Returns

ByteSize A ByteSize instance representing the specified value and unit.

From(double, ByteSizeUnit)

ByteSize.cs

Creates a ByteSize instance from a value and unit.

public static ByteSize From(double value, ByteSizeUnit unit)
Parameters
value double
The numeric value.
unit ByteSizeUnit
The unit of the value.
Returns

ByteSize A ByteSize instance representing the specified value and unit.

From(short, ByteSizeUnit)

ByteSize.cs

Creates a ByteSize instance from a value and unit.

public static ByteSize From(short value, ByteSizeUnit unit)
Parameters
value short
The numeric value.
unit ByteSizeUnit
The unit of the value.
Returns

ByteSize A ByteSize instance representing the specified value and unit.

From(int, ByteSizeUnit)

ByteSize.cs

Creates a ByteSize instance from a value and unit.

public static ByteSize From(int value, ByteSizeUnit unit)
Parameters
value int
The numeric value.
unit ByteSizeUnit
The unit of the value.
Returns

ByteSize A ByteSize instance representing the specified value and unit.

From(long, ByteSizeUnit)

ByteSize.cs

Creates a ByteSize instance from a value and unit.

public static ByteSize From(long value, ByteSizeUnit unit)
Parameters
value long
The numeric value.
unit ByteSizeUnit
The unit of the value.
Returns

ByteSize A ByteSize instance representing the specified value and unit.

From(float, ByteSizeUnit)

ByteSize.cs

Creates a ByteSize instance from a value and unit.

public static ByteSize From(float value, ByteSizeUnit unit)
Parameters
value float
The numeric value.
unit ByteSizeUnit
The unit of the value.
Returns

ByteSize A ByteSize instance representing the specified value and unit.

FromBytes overloads

FromBytes(byte)

ByteSize.Generated.cs

Creates a ByteSize instance from a byte value.

public static ByteSize FromBytes(byte value)
Parameters
value byte
The number of bytes (1 byte).
Returns

ByteSize A ByteSize instance representing the specified number of bytes.

FromBytes(double)

ByteSize.Generated.cs

Creates a ByteSize instance from a byte value.

public static ByteSize FromBytes(double value)
Parameters
value double
The number of bytes (1 byte).
Returns

ByteSize A ByteSize instance representing the specified number of bytes.

FromBytes(short)

ByteSize.Generated.cs

Creates a ByteSize instance from a byte value.

public static ByteSize FromBytes(short value)
Parameters
value short
The number of bytes (1 byte).
Returns

ByteSize A ByteSize instance representing the specified number of bytes.

FromBytes(int)

ByteSize.Generated.cs

Creates a ByteSize instance from a byte value.

public static ByteSize FromBytes(int value)
Parameters
value int
The number of bytes (1 byte).
Returns

ByteSize A ByteSize instance representing the specified number of bytes.

FromBytes(long)

ByteSize.Generated.cs

Creates a ByteSize instance from a byte value.

public static ByteSize FromBytes(long value)
Parameters
value long
The number of bytes (1 byte).
Returns

ByteSize A ByteSize instance representing the specified number of bytes.

FromBytes(float)

ByteSize.Generated.cs

Creates a ByteSize instance from a byte value.

public static ByteSize FromBytes(float value)
Parameters
value float
The number of bytes (1 byte).
Returns

ByteSize A ByteSize instance representing the specified number of bytes.

FromExaBytes overloads

FromExaBytes(byte)

ByteSize.Generated.cs

Creates a ByteSize instance from a exabyte value.

public static ByteSize FromExaBytes(byte value)
Parameters
value byte
The number of exabytes (1,000,000,000,000,000,000 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of exabytes.

FromExaBytes(double)

ByteSize.Generated.cs

Creates a ByteSize instance from a exabyte value.

public static ByteSize FromExaBytes(double value)
Parameters
value double
The number of exabytes (1,000,000,000,000,000,000 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of exabytes.

FromExaBytes(short)

ByteSize.Generated.cs

Creates a ByteSize instance from a exabyte value.

public static ByteSize FromExaBytes(short value)
Parameters
value short
The number of exabytes (1,000,000,000,000,000,000 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of exabytes.

FromExaBytes(int)

ByteSize.Generated.cs

Creates a ByteSize instance from a exabyte value.

public static ByteSize FromExaBytes(int value)
Parameters
value int
The number of exabytes (1,000,000,000,000,000,000 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of exabytes.

FromExaBytes(long)

ByteSize.Generated.cs

Creates a ByteSize instance from a exabyte value.

public static ByteSize FromExaBytes(long value)
Parameters
value long
The number of exabytes (1,000,000,000,000,000,000 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of exabytes.

FromExaBytes(float)

ByteSize.Generated.cs

Creates a ByteSize instance from a exabyte value.

public static ByteSize FromExaBytes(float value)
Parameters
value float
The number of exabytes (1,000,000,000,000,000,000 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of exabytes.

FromExbiBytes overloads

FromExbiBytes(byte)

ByteSize.Generated.cs

Creates a ByteSize instance from a exbibyte value.

public static ByteSize FromExbiBytes(byte value)
Parameters
value byte
The number of exbibytes (1,152,921,504,606,846,976 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of exbibytes.

FromExbiBytes(double)

ByteSize.Generated.cs

Creates a ByteSize instance from a exbibyte value.

public static ByteSize FromExbiBytes(double value)
Parameters
value double
The number of exbibytes (1,152,921,504,606,846,976 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of exbibytes.

FromExbiBytes(short)

ByteSize.Generated.cs

Creates a ByteSize instance from a exbibyte value.

public static ByteSize FromExbiBytes(short value)
Parameters
value short
The number of exbibytes (1,152,921,504,606,846,976 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of exbibytes.

FromExbiBytes(int)

ByteSize.Generated.cs

Creates a ByteSize instance from a exbibyte value.

public static ByteSize FromExbiBytes(int value)
Parameters
value int
The number of exbibytes (1,152,921,504,606,846,976 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of exbibytes.

FromExbiBytes(long)

ByteSize.Generated.cs

Creates a ByteSize instance from a exbibyte value.

public static ByteSize FromExbiBytes(long value)
Parameters
value long
The number of exbibytes (1,152,921,504,606,846,976 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of exbibytes.

FromExbiBytes(float)

ByteSize.Generated.cs

Creates a ByteSize instance from a exbibyte value.

public static ByteSize FromExbiBytes(float value)
Parameters
value float
The number of exbibytes (1,152,921,504,606,846,976 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of exbibytes.

FromFileLength overloads

FromFileLength(FileInfo)

ByteSize.cs

Creates a ByteSize instance from a file's length.

public static ByteSize FromFileLength(FileInfo fileInfo)
Parameters
fileInfo FileInfo
The file information.
Returns

ByteSize A ByteSize instance representing the file's size.

FromFileLength(string)

ByteSize.cs

Creates a ByteSize instance from a file's length.

public static ByteSize FromFileLength(string filePath)
Parameters
filePath string
The path to the file.
Returns

ByteSize A ByteSize instance representing the file's size.

FromGibiBytes overloads

FromGibiBytes(byte)

ByteSize.Generated.cs

Creates a ByteSize instance from a gibibyte value.

public static ByteSize FromGibiBytes(byte value)
Parameters
value byte
The number of gibibytes (1,073,741,824 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of gibibytes.

FromGibiBytes(double)

ByteSize.Generated.cs

Creates a ByteSize instance from a gibibyte value.

public static ByteSize FromGibiBytes(double value)
Parameters
value double
The number of gibibytes (1,073,741,824 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of gibibytes.

FromGibiBytes(short)

ByteSize.Generated.cs

Creates a ByteSize instance from a gibibyte value.

public static ByteSize FromGibiBytes(short value)
Parameters
value short
The number of gibibytes (1,073,741,824 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of gibibytes.

FromGibiBytes(int)

ByteSize.Generated.cs

Creates a ByteSize instance from a gibibyte value.

public static ByteSize FromGibiBytes(int value)
Parameters
value int
The number of gibibytes (1,073,741,824 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of gibibytes.

FromGibiBytes(long)

ByteSize.Generated.cs

Creates a ByteSize instance from a gibibyte value.

public static ByteSize FromGibiBytes(long value)
Parameters
value long
The number of gibibytes (1,073,741,824 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of gibibytes.

FromGibiBytes(float)

ByteSize.Generated.cs

Creates a ByteSize instance from a gibibyte value.

public static ByteSize FromGibiBytes(float value)
Parameters
value float
The number of gibibytes (1,073,741,824 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of gibibytes.

FromGigaBytes overloads

FromGigaBytes(byte)

ByteSize.Generated.cs

Creates a ByteSize instance from a gigabyte value.

public static ByteSize FromGigaBytes(byte value)
Parameters
value byte
The number of gigabytes (1,000,000,000 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of gigabytes.

FromGigaBytes(double)

ByteSize.Generated.cs

Creates a ByteSize instance from a gigabyte value.

public static ByteSize FromGigaBytes(double value)
Parameters
value double
The number of gigabytes (1,000,000,000 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of gigabytes.

FromGigaBytes(short)

ByteSize.Generated.cs

Creates a ByteSize instance from a gigabyte value.

public static ByteSize FromGigaBytes(short value)
Parameters
value short
The number of gigabytes (1,000,000,000 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of gigabytes.

FromGigaBytes(int)

ByteSize.Generated.cs

Creates a ByteSize instance from a gigabyte value.

public static ByteSize FromGigaBytes(int value)
Parameters
value int
The number of gigabytes (1,000,000,000 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of gigabytes.

FromGigaBytes(long)

ByteSize.Generated.cs

Creates a ByteSize instance from a gigabyte value.

public static ByteSize FromGigaBytes(long value)
Parameters
value long
The number of gigabytes (1,000,000,000 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of gigabytes.

FromGigaBytes(float)

ByteSize.Generated.cs

Creates a ByteSize instance from a gigabyte value.

public static ByteSize FromGigaBytes(float value)
Parameters
value float
The number of gigabytes (1,000,000,000 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of gigabytes.

FromKibiBytes overloads

FromKibiBytes(byte)

ByteSize.Generated.cs

Creates a ByteSize instance from a kibibyte value.

public static ByteSize FromKibiBytes(byte value)
Parameters
value byte
The number of kibibytes (1,024 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of kibibytes.

FromKibiBytes(double)

ByteSize.Generated.cs

Creates a ByteSize instance from a kibibyte value.

public static ByteSize FromKibiBytes(double value)
Parameters
value double
The number of kibibytes (1,024 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of kibibytes.

FromKibiBytes(short)

ByteSize.Generated.cs

Creates a ByteSize instance from a kibibyte value.

public static ByteSize FromKibiBytes(short value)
Parameters
value short
The number of kibibytes (1,024 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of kibibytes.

FromKibiBytes(int)

ByteSize.Generated.cs

Creates a ByteSize instance from a kibibyte value.

public static ByteSize FromKibiBytes(int value)
Parameters
value int
The number of kibibytes (1,024 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of kibibytes.

FromKibiBytes(long)

ByteSize.Generated.cs

Creates a ByteSize instance from a kibibyte value.

public static ByteSize FromKibiBytes(long value)
Parameters
value long
The number of kibibytes (1,024 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of kibibytes.

FromKibiBytes(float)

ByteSize.Generated.cs

Creates a ByteSize instance from a kibibyte value.

public static ByteSize FromKibiBytes(float value)
Parameters
value float
The number of kibibytes (1,024 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of kibibytes.

FromKiloBytes overloads

FromKiloBytes(byte)

ByteSize.Generated.cs

Creates a ByteSize instance from a kilobyte value.

public static ByteSize FromKiloBytes(byte value)
Parameters
value byte
The number of kilobytes (1,000 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of kilobytes.

FromKiloBytes(double)

ByteSize.Generated.cs

Creates a ByteSize instance from a kilobyte value.

public static ByteSize FromKiloBytes(double value)
Parameters
value double
The number of kilobytes (1,000 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of kilobytes.

FromKiloBytes(short)

ByteSize.Generated.cs

Creates a ByteSize instance from a kilobyte value.

public static ByteSize FromKiloBytes(short value)
Parameters
value short
The number of kilobytes (1,000 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of kilobytes.

FromKiloBytes(int)

ByteSize.Generated.cs

Creates a ByteSize instance from a kilobyte value.

public static ByteSize FromKiloBytes(int value)
Parameters
value int
The number of kilobytes (1,000 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of kilobytes.

FromKiloBytes(long)

ByteSize.Generated.cs

Creates a ByteSize instance from a kilobyte value.

public static ByteSize FromKiloBytes(long value)
Parameters
value long
The number of kilobytes (1,000 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of kilobytes.

FromKiloBytes(float)

ByteSize.Generated.cs

Creates a ByteSize instance from a kilobyte value.

public static ByteSize FromKiloBytes(float value)
Parameters
value float
The number of kilobytes (1,000 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of kilobytes.

FromMebiBytes overloads

FromMebiBytes(byte)

ByteSize.Generated.cs

Creates a ByteSize instance from a mebibyte value.

public static ByteSize FromMebiBytes(byte value)
Parameters
value byte
The number of mebibytes (1,048,576 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of mebibytes.

FromMebiBytes(double)

ByteSize.Generated.cs

Creates a ByteSize instance from a mebibyte value.

public static ByteSize FromMebiBytes(double value)
Parameters
value double
The number of mebibytes (1,048,576 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of mebibytes.

FromMebiBytes(short)

ByteSize.Generated.cs

Creates a ByteSize instance from a mebibyte value.

public static ByteSize FromMebiBytes(short value)
Parameters
value short
The number of mebibytes (1,048,576 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of mebibytes.

FromMebiBytes(int)

ByteSize.Generated.cs

Creates a ByteSize instance from a mebibyte value.

public static ByteSize FromMebiBytes(int value)
Parameters
value int
The number of mebibytes (1,048,576 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of mebibytes.

FromMebiBytes(long)

ByteSize.Generated.cs

Creates a ByteSize instance from a mebibyte value.

public static ByteSize FromMebiBytes(long value)
Parameters
value long
The number of mebibytes (1,048,576 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of mebibytes.

FromMebiBytes(float)

ByteSize.Generated.cs

Creates a ByteSize instance from a mebibyte value.

public static ByteSize FromMebiBytes(float value)
Parameters
value float
The number of mebibytes (1,048,576 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of mebibytes.

FromMegaBytes overloads

FromMegaBytes(byte)

ByteSize.Generated.cs

Creates a ByteSize instance from a megabyte value.

public static ByteSize FromMegaBytes(byte value)
Parameters
value byte
The number of megabytes (1,000,000 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of megabytes.

FromMegaBytes(double)

ByteSize.Generated.cs

Creates a ByteSize instance from a megabyte value.

public static ByteSize FromMegaBytes(double value)
Parameters
value double
The number of megabytes (1,000,000 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of megabytes.

FromMegaBytes(short)

ByteSize.Generated.cs

Creates a ByteSize instance from a megabyte value.

public static ByteSize FromMegaBytes(short value)
Parameters
value short
The number of megabytes (1,000,000 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of megabytes.

FromMegaBytes(int)

ByteSize.Generated.cs

Creates a ByteSize instance from a megabyte value.

public static ByteSize FromMegaBytes(int value)
Parameters
value int
The number of megabytes (1,000,000 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of megabytes.

FromMegaBytes(long)

ByteSize.Generated.cs

Creates a ByteSize instance from a megabyte value.

public static ByteSize FromMegaBytes(long value)
Parameters
value long
The number of megabytes (1,000,000 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of megabytes.

FromMegaBytes(float)

ByteSize.Generated.cs

Creates a ByteSize instance from a megabyte value.

public static ByteSize FromMegaBytes(float value)
Parameters
value float
The number of megabytes (1,000,000 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of megabytes.

FromPebiBytes overloads

FromPebiBytes(byte)

ByteSize.Generated.cs

Creates a ByteSize instance from a pebibyte value.

public static ByteSize FromPebiBytes(byte value)
Parameters
value byte
The number of pebibytes (1,125,899,906,842,624 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of pebibytes.

FromPebiBytes(double)

ByteSize.Generated.cs

Creates a ByteSize instance from a pebibyte value.

public static ByteSize FromPebiBytes(double value)
Parameters
value double
The number of pebibytes (1,125,899,906,842,624 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of pebibytes.

FromPebiBytes(short)

ByteSize.Generated.cs

Creates a ByteSize instance from a pebibyte value.

public static ByteSize FromPebiBytes(short value)
Parameters
value short
The number of pebibytes (1,125,899,906,842,624 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of pebibytes.

FromPebiBytes(int)

ByteSize.Generated.cs

Creates a ByteSize instance from a pebibyte value.

public static ByteSize FromPebiBytes(int value)
Parameters
value int
The number of pebibytes (1,125,899,906,842,624 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of pebibytes.

FromPebiBytes(long)

ByteSize.Generated.cs

Creates a ByteSize instance from a pebibyte value.

public static ByteSize FromPebiBytes(long value)
Parameters
value long
The number of pebibytes (1,125,899,906,842,624 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of pebibytes.

FromPebiBytes(float)

ByteSize.Generated.cs

Creates a ByteSize instance from a pebibyte value.

public static ByteSize FromPebiBytes(float value)
Parameters
value float
The number of pebibytes (1,125,899,906,842,624 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of pebibytes.

FromPetaBytes overloads

FromPetaBytes(byte)

ByteSize.Generated.cs

Creates a ByteSize instance from a petabyte value.

public static ByteSize FromPetaBytes(byte value)
Parameters
value byte
The number of petabytes (1,000,000,000,000,000 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of petabytes.

FromPetaBytes(double)

ByteSize.Generated.cs

Creates a ByteSize instance from a petabyte value.

public static ByteSize FromPetaBytes(double value)
Parameters
value double
The number of petabytes (1,000,000,000,000,000 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of petabytes.

FromPetaBytes(short)

ByteSize.Generated.cs

Creates a ByteSize instance from a petabyte value.

public static ByteSize FromPetaBytes(short value)
Parameters
value short
The number of petabytes (1,000,000,000,000,000 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of petabytes.

FromPetaBytes(int)

ByteSize.Generated.cs

Creates a ByteSize instance from a petabyte value.

public static ByteSize FromPetaBytes(int value)
Parameters
value int
The number of petabytes (1,000,000,000,000,000 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of petabytes.

FromPetaBytes(long)

ByteSize.Generated.cs

Creates a ByteSize instance from a petabyte value.

public static ByteSize FromPetaBytes(long value)
Parameters
value long
The number of petabytes (1,000,000,000,000,000 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of petabytes.

FromPetaBytes(float)

ByteSize.Generated.cs

Creates a ByteSize instance from a petabyte value.

public static ByteSize FromPetaBytes(float value)
Parameters
value float
The number of petabytes (1,000,000,000,000,000 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of petabytes.

FromTebiBytes overloads

FromTebiBytes(byte)

ByteSize.Generated.cs

Creates a ByteSize instance from a tebibyte value.

public static ByteSize FromTebiBytes(byte value)
Parameters
value byte
The number of tebibytes (1,099,511,627,776 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of tebibytes.

FromTebiBytes(double)

ByteSize.Generated.cs

Creates a ByteSize instance from a tebibyte value.

public static ByteSize FromTebiBytes(double value)
Parameters
value double
The number of tebibytes (1,099,511,627,776 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of tebibytes.

FromTebiBytes(short)

ByteSize.Generated.cs

Creates a ByteSize instance from a tebibyte value.

public static ByteSize FromTebiBytes(short value)
Parameters
value short
The number of tebibytes (1,099,511,627,776 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of tebibytes.

FromTebiBytes(int)

ByteSize.Generated.cs

Creates a ByteSize instance from a tebibyte value.

public static ByteSize FromTebiBytes(int value)
Parameters
value int
The number of tebibytes (1,099,511,627,776 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of tebibytes.

FromTebiBytes(long)

ByteSize.Generated.cs

Creates a ByteSize instance from a tebibyte value.

public static ByteSize FromTebiBytes(long value)
Parameters
value long
The number of tebibytes (1,099,511,627,776 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of tebibytes.

FromTebiBytes(float)

ByteSize.Generated.cs

Creates a ByteSize instance from a tebibyte value.

public static ByteSize FromTebiBytes(float value)
Parameters
value float
The number of tebibytes (1,099,511,627,776 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of tebibytes.

FromTeraBytes overloads

FromTeraBytes(byte)

ByteSize.Generated.cs

Creates a ByteSize instance from a terabyte value.

public static ByteSize FromTeraBytes(byte value)
Parameters
value byte
The number of terabytes (1,000,000,000,000 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of terabytes.

FromTeraBytes(double)

ByteSize.Generated.cs

Creates a ByteSize instance from a terabyte value.

public static ByteSize FromTeraBytes(double value)
Parameters
value double
The number of terabytes (1,000,000,000,000 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of terabytes.

FromTeraBytes(short)

ByteSize.Generated.cs

Creates a ByteSize instance from a terabyte value.

public static ByteSize FromTeraBytes(short value)
Parameters
value short
The number of terabytes (1,000,000,000,000 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of terabytes.

FromTeraBytes(int)

ByteSize.Generated.cs

Creates a ByteSize instance from a terabyte value.

public static ByteSize FromTeraBytes(int value)
Parameters
value int
The number of terabytes (1,000,000,000,000 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of terabytes.

FromTeraBytes(long)

ByteSize.Generated.cs

Creates a ByteSize instance from a terabyte value.

public static ByteSize FromTeraBytes(long value)
Parameters
value long
The number of terabytes (1,000,000,000,000 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of terabytes.

FromTeraBytes(float)

ByteSize.Generated.cs

Creates a ByteSize instance from a terabyte value.

public static ByteSize FromTeraBytes(float value)
Parameters
value float
The number of terabytes (1,000,000,000,000 bytes).
Returns

ByteSize A ByteSize instance representing the specified number of terabytes.

GetHashCode()

ByteSize.cs
public override int GetHashCode()

Returns

int

No documentation is available.

GetValue(ByteSizeUnit)

ByteSize.cs

Converts the byte size to the specified unit.

public double GetValue(ByteSizeUnit unit)

Parameters

unit ByteSizeUnit
The unit to convert to.

Returns

double The value in the specified unit.

Multiply(long)

ByteSize.cs

Scales this byte size by a factor.

public ByteSize Multiply(long multiplier)

Parameters

multiplier long
The factor to scale by.

Returns

ByteSize The scaled byte size.

Parse overloads

Parse(ReadOnlySpan<byte>)

ByteSize.cs

Parses a span of UTF-8 characters into a ByteSize value.

public static ByteSize Parse(ReadOnlySpan<byte> utf8Text)
Parameters
utf8Text ReadOnlySpan<byte>
The span of UTF-8 characters to parse.
Returns

ByteSize The result of parsing utf8Text.

Exceptions
FormatException
utf8Text is not in the correct format.

Parse(ReadOnlySpan<char>, IFormatProvider?)

ByteSize.cs

Parses a span of characters into a ByteSize value.

public static ByteSize Parse(ReadOnlySpan<char> s, IFormatProvider? provider)
Parameters
s ReadOnlySpan<char>
The span of characters to parse.
provider IFormatProvider?
An object that provides culture-specific formatting information about s.
Returns

ByteSize The result of parsing s.

Exceptions
FormatException
s is not in the correct format.

Parse(string, IFormatProvider?)

ByteSize.cs

Converts the string representation of a byte size to its ByteSize equivalent.

public static ByteSize Parse(string text, IFormatProvider? formatProvider)
Parameters
text string
A string containing a byte size to convert.
formatProvider IFormatProvider?
An object that supplies culture-specific formatting information.
Returns

ByteSize A ByteSize equivalent to the byte size specified in text.

Exceptions
FormatException
text is not in a valid format.

Subtract(ByteSize)

ByteSize.cs

Subtracts a byte size value from this instance.

public ByteSize Subtract(ByteSize other)

Parameters

other ByteSize
The value to subtract.

Returns

ByteSize The result of the subtraction.

ToString overloads

ToString()

ByteSize.cs
public override string ToString()
Returns

string

No documentation is available.

ToString(ByteSizeUnit)

ByteSize.cs
public string ToString(ByteSizeUnit unit)
Parameters
unit ByteSizeUnit
Returns

string

No documentation is available.

ToString(ByteSizeUnit, IFormatProvider?)

ByteSize.cs
public string ToString(ByteSizeUnit unit, IFormatProvider? formatProvider)
Parameters
unit ByteSizeUnit
formatProvider IFormatProvider?
Returns

string

No documentation is available.

ToString(IFormatProvider?)

ByteSize.cs
public string ToString(IFormatProvider? formatProvider)
Parameters
formatProvider IFormatProvider?
Returns

string

No documentation is available.

ToString(string?)

ByteSize.cs

Convert value to string

public string ToString(string? format)
Parameters
format string?
Allowed formats:
  • G: Find the best unit (B, kB, MB, GB, etc.), and use G format for the value
  • G2: Find the best unit (B, kB, MB, GB, etc.), and use F2 format for the value
  • Gi: Find the best unit (B, kiB, MiB, GiB, etc.), and use G format for the value
  • Gi2: Find the best unit (B, kiB, MiB, GiB, etc.), and use F2 format for the value
  • F, F2, Fi, Fi2: Synonyms of G, G2, Gi, Gi2
  • B, kB, kiB, MB, MiB, GB, GiB, TB, TiB, PB, PiB, EB, EiB: Use the provided unit, and use G format for the value. If a number is provided (e.g. kB3), it use Fn (e.g. F3) format to convert the value to string.
Returns

string

Exceptions
FormatException
The provided format is not valid

ToString(string?, IFormatProvider?)

ByteSize.cs

Convert value to string

public string ToString(string? format, IFormatProvider? formatProvider)
Parameters
format string?
Allowed formats:
  • G: Find the best unit (B, kB, MB, GB, etc.), and use G format for the value
  • G2: Find the best unit (B, kB, MB, GB, etc.), and use F2 format for the value
  • Gi: Find the best unit (B, kiB, MiB, GiB, etc.), and use G format for the value
  • Gi2: Find the best unit (B, kiB, MiB, GiB, etc.), and use F2 format for the value
  • F, F2, Fi, Fi2: Synonyms of G, G2, Gi, Gi2
  • B, kB, kiB, MB, MiB, GB, GiB, TB, TiB, PB, PiB, EB, EiB: Use the provided unit, and use G format for the value. If a number is provided (e.g. kB3), it use Fn (e.g. F3) format to convert the value to string.
formatProvider IFormatProvider?
Returns

string

Exceptions
FormatException
The provided format is not valid

TryFormat overloads

TryFormat(Span<byte>, int, ReadOnlySpan<char>, IFormatProvider?)

ByteSize.cs

Tries to format the value as UTF-8 into the provided span of bytes.

public bool TryFormat(Span<byte> utf8Destination, out int bytesWritten, ReadOnlySpan<char> format, IFormatProvider? provider)
Parameters
utf8Destination Span<byte>
The span in which to write this instance's value formatted as UTF-8.
bytesWritten int
When this method returns, contains the number of bytes that were written in utf8Destination.
format ReadOnlySpan<char>
A span containing the characters that represent a standard or custom format string.
provider IFormatProvider?
An optional object that supplies culture-specific formatting information.
Returns

bool true if the formatting was successful; otherwise, false.

TryFormat(Span<char>, int, ReadOnlySpan<char>, IFormatProvider?)

ByteSize.cs

Tries to format the value into the provided span of characters.

public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider? provider)
Parameters
destination Span<char>
The span in which to write this instance's value formatted as a span of characters.
charsWritten int
When this method returns, contains the number of characters that were written in destination.
format ReadOnlySpan<char>
A span containing the characters that represent a standard or custom format string.
provider IFormatProvider?
An optional object that supplies culture-specific formatting information for destination.
Returns

bool true if the formatting was successful; otherwise, false.

TryParse overloads

TryParse(ReadOnlySpan<byte>, ByteSize)

ByteSize.cs

Tries to parse a span of UTF-8 characters into a ByteSize value.

public static bool TryParse(ReadOnlySpan<byte> utf8Text, out ByteSize result)
Parameters
utf8Text ReadOnlySpan<byte>
The span of UTF-8 characters to parse.
result ByteSize
When this method returns, contains the result of successfully parsing utf8Text, or an undefined value on failure.
Returns

bool true if utf8Text was successfully parsed; otherwise, false.

TryParse(ReadOnlySpan<char>, IFormatProvider?, ByteSize)

ByteSize.cs

Tries to parse a span of characters into a ByteSize value.

public static bool TryParse(ReadOnlySpan<char> s, IFormatProvider? provider, out ByteSize result)
Parameters
s ReadOnlySpan<char>
The span of characters to parse.
provider IFormatProvider?
An object that provides culture-specific formatting information about s.
result ByteSize
When this method returns, contains the result of successfully parsing s, or an undefined value on failure.
Returns

bool true if s was successfully parsed; otherwise, false.

TryParse(string, ByteSize)

ByteSize.cs

Tries to convert the string representation of a byte size to its ByteSize equivalent.

public static bool TryParse(string text, out ByteSize result)
Parameters
text string
A string containing a byte size to convert.
result ByteSize
When this method returns, contains the ByteSize equivalent to the byte size specified in text, if the conversion succeeded, or zero if the conversion failed.
Returns

bool true if text was converted successfully; otherwise, false.

TryParse(string?, IFormatProvider?, ByteSize)

ByteSize.cs

Tries to convert the string representation of a byte size to its ByteSize equivalent.

public static bool TryParse(string? text, IFormatProvider? formatProvider, out ByteSize result)
Parameters
text string?
A string containing a byte size to convert.
formatProvider IFormatProvider?
An object that supplies culture-specific formatting information.
result ByteSize
When this method returns, contains the ByteSize equivalent to the byte size specified in text, if the conversion succeeded, or zero if the conversion failed.
Returns

bool true if text was converted successfully; otherwise, false.

Operators

NameDescription
operator +(ByteSize, ByteSize)
operator /(ByteSize, long)Divides a byte size by a factor.
operator ==(ByteSize, ByteSize)
operator >(ByteSize, ByteSize)
operator >=(ByteSize, ByteSize)
implicit operator ByteSize(long)
operator !=(ByteSize, ByteSize)
operator <(ByteSize, ByteSize)
operator <=(ByteSize, ByteSize)
operator *(ByteSize, long)Scales a byte size by a factor.
operator *(long, ByteSize)Scales a byte size by a factor.
operator -(ByteSize, ByteSize)

operator +(ByteSize, ByteSize)

ByteSize.cs
public static ByteSize operator +(ByteSize value1, ByteSize value2)

Parameters

value1 ByteSize
value2 ByteSize

Returns

ByteSize

No documentation is available.

operator /(ByteSize, long)

ByteSize.cs

Divides a byte size by a factor.

public static ByteSize operator /(ByteSize value, long divisor)

Parameters

value ByteSize
divisor long

Returns

ByteSize

operator ==(ByteSize, ByteSize)

ByteSize.cs
public static bool operator ==(ByteSize value1, ByteSize value2)

Parameters

value1 ByteSize
value2 ByteSize

Returns

bool

No documentation is available.

operator >(ByteSize, ByteSize)

ByteSize.cs
public static bool operator >(ByteSize value1, ByteSize value2)

Parameters

value1 ByteSize
value2 ByteSize

Returns

bool

No documentation is available.

operator >=(ByteSize, ByteSize)

ByteSize.cs
public static bool operator >=(ByteSize value1, ByteSize value2)

Parameters

value1 ByteSize
value2 ByteSize

Returns

bool

No documentation is available.

implicit operator ByteSize(long)

ByteSize.cs
public static implicit operator ByteSize(long value)

Parameters

value long

Returns

ByteSize

No documentation is available.

operator !=(ByteSize, ByteSize)

ByteSize.cs
public static bool operator !=(ByteSize value1, ByteSize value2)

Parameters

value1 ByteSize
value2 ByteSize

Returns

bool

No documentation is available.

operator <(ByteSize, ByteSize)

ByteSize.cs
public static bool operator <(ByteSize value1, ByteSize value2)

Parameters

value1 ByteSize
value2 ByteSize

Returns

bool

No documentation is available.

operator <=(ByteSize, ByteSize)

ByteSize.cs
public static bool operator <=(ByteSize value1, ByteSize value2)

Parameters

value1 ByteSize
value2 ByteSize

Returns

bool

No documentation is available.

op_Multiply overloads

operator *(ByteSize, long)

ByteSize.cs

Scales a byte size by a factor.

public static ByteSize operator *(ByteSize value, long multiplier)
Parameters
value ByteSize
multiplier long
Returns

ByteSize

operator *(long, ByteSize)

ByteSize.cs

Scales a byte size by a factor.

public static ByteSize operator *(long multiplier, ByteSize value)
Parameters
multiplier long
value ByteSize
Returns

ByteSize

operator -(ByteSize, ByteSize)

ByteSize.cs
public static ByteSize operator -(ByteSize value1, ByteSize value2)

Parameters

value1 ByteSize
value2 ByteSize

Returns

ByteSize

No documentation is available.