Click or drag to resize

NiceFormatter.Sample(Byte[], Int32) Method

Converts a buffer into a nicely formatted string where leading and trailing bytes of a maximum length are displayed, but excess middle bytes are replaced with a count placeholder. It therefore displays a sample of a buffer of arbitrary length. The middle truncation is skipped if it is less than 8 bytes long.

Namespace: Orthogonal.Common.Basic
Assembly: Orthogonal.Common.Basic (in Orthogonal.Common.Basic.dll) Version: 2025-03-15 14:42 GMT+11
Syntax
C#
public static string Sample(
	this byte[] buffer,
	int sampleLength = 32
)

Parameters

buffer  Byte[]
The buffer to nicely format as a sample.
sampleLength  Int32  (Optional)
The length of the leading and trailing bytes to be shown as a sample of the buffer.

Return Value

String
A string representation sample of a buffer.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type Byte[]. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).
Exceptions
ExceptionCondition
ArgumentOutOfRangeExceptionThrown if sampleLength is less than one.
Example
C#
// Buffer sample with 8 bytes leading and trailing bytes displayed
var buff = new byte[1000];
string sample = buff.Sample(8);
Console.WriteLine(sample);
// Produces…
// <1000>0000000000000000…◄984►…0000000000000000
See Also