BitConverter.TryWriteBytes Method

Definition

Overloads

TryWriteBytes(Span<Byte>, Int64)

Converts a 64-bit signed integer into a span of bytes.

TryWriteBytes(Span<Byte>, Boolean)

Converts a Boolean into a span of bytes.

TryWriteBytes(Span<Byte>, Char)

Converts a character into a span of bytes.

TryWriteBytes(Span<Byte>, Double)

Converts a double-precision floating-point value into a span of bytes.

TryWriteBytes(Span<Byte>, Half)

Converts a half-precision floating-point value into a span of bytes.

TryWriteBytes(Span<Byte>, Int128)

Converts a 128-bit signed integer into a span of bytes.

TryWriteBytes(Span<Byte>, Int16)

Converts a 16-bit signed integer into a span of bytes.

TryWriteBytes(Span<Byte>, Int32)

Converts a 32-bit signed integer into a span of bytes.

TryWriteBytes(Span<Byte>, Single)

Converts a single-precision floating-point value into a span of bytes.

TryWriteBytes(Span<Byte>, UInt128)

Converts a 128-bit unsigned integer into a span of bytes.

TryWriteBytes(Span<Byte>, UInt16)

Converts an unsigned 16-bit integer into a span of bytes.

TryWriteBytes(Span<Byte>, UInt32)

Converts a 32-bit unsigned integer into a span of bytes.

TryWriteBytes(Span<Byte>, UInt64)

Converts an unsigned 64-bit integer into a span of bytes.

TryWriteBytes(Span<Byte>, Int64)

Source:
BitConverter.cs
Source:
BitConverter.cs
Source:
BitConverter.cs

Converts a 64-bit signed integer into a span of bytes.

C#
public static bool TryWriteBytes(Span<byte> destination, long value);

Parameters

destination
Span<Byte>

When this method returns, the bytes representing the converted 64-bit signed integer.

value
Int64

The 64-bit signed integer to convert.

Returns

true if the conversion was successful; false otherwise.

Applies to

.NET 10 and other versions
Product Versions
.NET Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Standard 2.1

TryWriteBytes(Span<Byte>, Boolean)

Source:
BitConverter.cs
Source:
BitConverter.cs
Source:
BitConverter.cs

Converts a Boolean into a span of bytes.

C#
public static bool TryWriteBytes(Span<byte> destination, bool value);

Parameters

destination
Span<Byte>

When this method returns, the bytes representing the converted Boolean.

value
Boolean

The Boolean to convert.

Returns

true if the conversion was successful; false otherwise.

Applies to

.NET 10 and other versions
Product Versions
.NET Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Standard 2.1

TryWriteBytes(Span<Byte>, Char)

Source:
BitConverter.cs
Source:
BitConverter.cs
Source:
BitConverter.cs

Converts a character into a span of bytes.

C#
public static bool TryWriteBytes(Span<byte> destination, char value);

Parameters

destination
Span<Byte>

When this method returns, the bytes representing the converted character.

value
Char

The character to convert.

Returns

true if the conversion was successful; false otherwise.

Applies to

.NET 10 and other versions
Product Versions
.NET Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Standard 2.1

TryWriteBytes(Span<Byte>, Double)

Source:
BitConverter.cs
Source:
BitConverter.cs
Source:
BitConverter.cs

Converts a double-precision floating-point value into a span of bytes.

C#
public static bool TryWriteBytes(Span<byte> destination, double value);

Parameters

destination
Span<Byte>

When this method returns, the bytes representing the converted double-precision floating-point value.

value
Double

The double-precision floating-point value to convert.

Returns

true if the conversion was successful; false otherwise.

Applies to

.NET 10 and other versions
Product Versions
.NET Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Standard 2.1

TryWriteBytes(Span<Byte>, Half)

Source:
BitConverter.cs
Source:
BitConverter.cs
Source:
BitConverter.cs

Converts a half-precision floating-point value into a span of bytes.

C#
public static bool TryWriteBytes(Span<byte> destination, Half value);

Parameters

destination
Span<Byte>

When this method returns, the bytes representing the converted half-precision floating-point value.

value
Half

The half-precision floating-point value to convert.

Returns

true if the conversion was successful; false otherwise.

Applies to

.NET 10 and other versions
Product Versions
.NET 6, 7, 8, 9, 10

TryWriteBytes(Span<Byte>, Int128)

Source:
BitConverter.cs

Converts a 128-bit signed integer into a span of bytes.

C#
public static bool TryWriteBytes(Span<byte> destination, Int128 value);

Parameters

destination
Span<Byte>

When this method returns, the bytes representing the converted 128-bit signed integer.

value
Int128

The 128-bit signed integer to convert.

Returns

true if the conversion was successful; false otherwise.

Applies to

.NET 10 and .NET 9
Product Versions
.NET 9, 10

TryWriteBytes(Span<Byte>, Int16)

Source:
BitConverter.cs
Source:
BitConverter.cs
Source:
BitConverter.cs

Converts a 16-bit signed integer into a span of bytes.

C#
public static bool TryWriteBytes(Span<byte> destination, short value);

Parameters

destination
Span<Byte>

When this method returns, the bytes representing the converted 16-bit signed integer.

value
Int16

The 16-bit signed integer to convert.

Returns

true if the conversion was successful; false otherwise.

Applies to

.NET 10 and other versions
Product Versions
.NET Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Standard 2.1

TryWriteBytes(Span<Byte>, Int32)

Source:
BitConverter.cs
Source:
BitConverter.cs
Source:
BitConverter.cs

Converts a 32-bit signed integer into a span of bytes.

C#
public static bool TryWriteBytes(Span<byte> destination, int value);

Parameters

destination
Span<Byte>

When this method returns, the bytes representing the converted 32-bit signed integer.

value
Int32

The 32-bit signed integer to convert.

Returns

true if the conversion was successful; false otherwise.

Applies to

.NET 10 and other versions
Product Versions
.NET Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Standard 2.1

TryWriteBytes(Span<Byte>, Single)

Source:
BitConverter.cs
Source:
BitConverter.cs
Source:
BitConverter.cs

Converts a single-precision floating-point value into a span of bytes.

C#
public static bool TryWriteBytes(Span<byte> destination, float value);

Parameters

destination
Span<Byte>

When this method returns, the bytes representing the converted single-precision floating-point value.

value
Single

The single-precision floating-point value to convert.

Returns

true if the conversion was successful; false otherwise.

Applies to

.NET 10 and other versions
Product Versions
.NET Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Standard 2.1

TryWriteBytes(Span<Byte>, UInt128)

Source:
BitConverter.cs

Important

This API is not CLS-compliant.

Converts a 128-bit unsigned integer into a span of bytes.

C#
[System.CLSCompliant(false)]
public static bool TryWriteBytes(Span<byte> destination, UInt128 value);

Parameters

destination
Span<Byte>

When this method returns, the bytes representing the converted 128-bit unsigned integer.

value
UInt128

The 128-bit unsigned integer to convert.

Returns

true if the conversion was successful; false otherwise.

Attributes

Applies to

.NET 10 and .NET 9
Product Versions
.NET 9, 10

TryWriteBytes(Span<Byte>, UInt16)

Source:
BitConverter.cs
Source:
BitConverter.cs
Source:
BitConverter.cs

Important

This API is not CLS-compliant.

Converts an unsigned 16-bit integer into a span of bytes.

C#
[System.CLSCompliant(false)]
public static bool TryWriteBytes(Span<byte> destination, ushort value);

Parameters

destination
Span<Byte>

When this method returns, the bytes representing the converted unsigned 16-bit integer.

value
UInt16

The unsigned 16-bit integer to convert.

Returns

true if the conversion was successful; false otherwise.

Attributes

Applies to

.NET 10 and other versions
Product Versions
.NET Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Standard 2.1

TryWriteBytes(Span<Byte>, UInt32)

Source:
BitConverter.cs
Source:
BitConverter.cs
Source:
BitConverter.cs

Important

This API is not CLS-compliant.

Converts a 32-bit unsigned integer into a span of bytes.

C#
[System.CLSCompliant(false)]
public static bool TryWriteBytes(Span<byte> destination, uint value);

Parameters

destination
Span<Byte>

When this method returns, the bytes representing the converted unsigned 32-bit integer.

value
UInt32

The unsigned 32-bit integer to convert.

Returns

true if the conversion was successful; false otherwise.

Attributes

Applies to

.NET 10 and other versions
Product Versions
.NET Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Standard 2.1

TryWriteBytes(Span<Byte>, UInt64)

Source:
BitConverter.cs
Source:
BitConverter.cs
Source:
BitConverter.cs

Important

This API is not CLS-compliant.

Converts an unsigned 64-bit integer into a span of bytes.

C#
[System.CLSCompliant(false)]
public static bool TryWriteBytes(Span<byte> destination, ulong value);

Parameters

destination
Span<Byte>

When this method returns, the bytes representing the converted unsigned 64-bit integer.

value
UInt64

The unsigned 64-bit integer to convert.

Returns

true if the conversion was successful; false otherwise.

Attributes

Applies to

.NET 10 and other versions
Product Versions
.NET Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Standard 2.1