Struct Bytes
Represents a read-only view over a sequence of bytes.
public readonly struct Bytes : IReadOnlyList<byte>, IReadOnlyCollection<byte>, IEnumerable<byte>, IEnumerable, ICloneable, IEquatable<Bytes>, IEquatable<byte[]>, IComparable<Bytes>, IComparable<byte[]>, IComparable, IComparisonOperators<Bytes, Bytes, bool>, IEqualityOperators<Bytes, Bytes, bool>, IComparisonOperators<Bytes, byte[], bool>, IEqualityOperators<Bytes, byte[], bool>, IAdditionOperators<Bytes, Bytes, Bytes>, IAdditionOperators<Bytes, byte[], Bytes>
- Implements
-
IEquatable<byte[]>IComparable<byte[]>
- Inherited Members
- Extension Methods
Properties
Count
Gets the number of bytes stored in this Bytes instance.
public int Count { get; }
Property Value
Empty
Gets an empty Bytes instance with no data.
public static Bytes Empty { get; }
Property Value
this[int]
Gets the byte at the specified index.
public byte this[int index] { get; }
Parameters
indexintThe zero-based index of the element to get.
Property Value
- byte
The byte at the specified
index.
Methods
Clone()
Creates a new copy of the current Bytes object.
public object Clone()
Returns
CompareTo(byte[]?)
public int CompareTo(byte[]? other)
Parameters
Returns
- int
A signed integer that indicates the relative order of the compared objects. 0 if they are equal, less than 0 if this is less than
other, and greater than 0 if this is greater.
CompareTo(object?)
Compares the current instance with another object of the same type.
public int CompareTo(object? obj)
Parameters
Returns
- int
A value indicating the relative order of the objects.
Exceptions
- InvalidOperationException
If
objis not a valid type.
CompareTo(Bytes)
public int CompareTo(Bytes other)
Parameters
Returns
- int
A signed integer that indicates the relative order of the compared objects. 0 if they are equal, less than 0 if this is less than
other, and greater than 0 if this is greater.
CopyTo(byte[], int, int?)
Copies the contents of this Bytes into the specified array
starting at index and using an optional length.
public void CopyTo(byte[] array, int index, int? length = null)
Parameters
arraybyte[]The target array.
indexintThe destination index in
array. If negative, it is offset from the end ofarray.lengthint?Number of bytes to copy. If null, copies as many as possible.
CopyTo(Stream, int, int?)
Writes the contents of this Bytes to a Stream
starting at the specified index and using an optional length.
public void CopyTo(Stream s, int index, int? length = null)
Parameters
sStreamThe stream to write to.
indexintThe source index in the Utils.Objects.Bytes._innerBytes array.
lengthint?Number of bytes to write. If null, writes as many as possible.
Equals(byte[]?)
Determines whether the specified byte array is equal to the current Bytes.
public bool Equals(byte[]? other)
Parameters
Returns
Equals(object?)
Indicates whether this instance and a specified object are equal.
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.
Equals(Bytes)
public bool Equals(Bytes other)
Parameters
Returns
GetEnumerator()
Returns an enumerator that iterates through the byte array.
public IEnumerator<byte> GetEnumerator()
Returns
GetHashCode()
Returns the hash code for this instance.
public override int GetHashCode()
Returns
- int
A 32-bit signed integer that is the hash code for this instance.
Parse(string)
Creates a Bytes object from a string of hexadecimal numbers separated by spaces or common delimiters.
public static Bytes Parse(string s)
Parameters
sstringA string containing hexadecimal numbers to parse.
Returns
Exceptions
- FormatException
Thrown if the string contains invalid hexadecimal values.
ToArray()
Returns a copy of the underlying byte array.
public byte[] ToArray()
Returns
ToString()
Returns a string that represents the byte array in hexadecimal format.
public override string ToString()
Returns
Operators
operator +(byte[], Bytes)
public static Bytes operator +(byte[] left, Bytes right)
Parameters
Returns
operator +(Bytes, byte[])
public static Bytes operator +(Bytes left, byte[] right)
Parameters
Returns
operator +(Bytes, Bytes)
Concatenates two Bytes instances into a new sequence.
public static Bytes operator +(Bytes left, Bytes right)
Parameters
Returns
operator ==(byte[], Bytes)
public static bool operator ==(byte[] left, Bytes right)
Parameters
Returns
operator ==(Bytes, byte[]?)
public static bool operator ==(Bytes left, byte[]? right)
Parameters
Returns
operator ==(Bytes, Bytes)
Determines whether two Bytes instances represent identical sequences.
public static bool operator ==(Bytes left, Bytes right)
Parameters
Returns
operator >(byte[], Bytes)
Determines whether a raw byte array is lexicographically greater than a wrapped sequence.
public static bool operator >(byte[] left, Bytes right)
Parameters
Returns
operator >(Bytes, byte[])
Determines whether a Bytes instance is lexicographically greater than a raw array.
public static bool operator >(Bytes left, byte[] right)
Parameters
Returns
operator >(Bytes, Bytes)
Determines whether one Bytes instance is lexicographically greater than another.
public static bool operator >(Bytes left, Bytes right)
Parameters
Returns
operator >=(byte[], Bytes)
Determines whether a raw byte array is lexicographically greater than or equal to a wrapped sequence.
public static bool operator >=(byte[] left, Bytes right)
Parameters
Returns
operator >=(Bytes, byte[])
Determines whether a Bytes instance is lexicographically greater than or equal to a raw array.
public static bool operator >=(Bytes left, byte[] right)
Parameters
Returns
operator >=(Bytes, Bytes)
Determines whether one Bytes instance is lexicographically greater than or equal to another.
public static bool operator >=(Bytes left, Bytes right)
Parameters
Returns
implicit operator Bytes(byte[])
public static implicit operator Bytes(byte[] bytes)
Parameters
bytesbyte[]
Returns
implicit operator byte[](Bytes)
public static implicit operator byte[](Bytes bytes)
Parameters
bytesBytes
Returns
- byte[]
operator !=(byte[], Bytes)
public static bool operator !=(byte[] left, Bytes right)
Parameters
Returns
operator !=(Bytes, byte[]?)
public static bool operator !=(Bytes left, byte[]? right)
Parameters
Returns
operator !=(Bytes, Bytes)
Determines whether two Bytes instances do not represent identical sequences.
public static bool operator !=(Bytes left, Bytes right)
Parameters
Returns
operator <(byte[], Bytes)
Determines whether a raw byte array is lexicographically less than a wrapped sequence.
public static bool operator <(byte[] left, Bytes right)
Parameters
Returns
operator <(Bytes, byte[])
Determines whether a Bytes instance is lexicographically less than a raw array.
public static bool operator <(Bytes left, byte[] right)
Parameters
Returns
operator <(Bytes, Bytes)
Determines whether one Bytes instance is lexicographically less than another.
public static bool operator <(Bytes left, Bytes right)
Parameters
Returns
operator <=(byte[], Bytes)
Determines whether a raw byte array is lexicographically less than or equal to a wrapped sequence.
public static bool operator <=(byte[] left, Bytes right)
Parameters
Returns
operator <=(Bytes, byte[])
Determines whether a Bytes instance is lexicographically less than or equal to a raw array.
public static bool operator <=(Bytes left, byte[] right)
Parameters
Returns
operator <=(Bytes, Bytes)
Determines whether one Bytes instance is lexicographically less than or equal to another.
public static bool operator <=(Bytes left, Bytes right)