Show / Hide Table of Contents

TryReadInt16 Method

TryReadInt16(out short, int, bool)

Try to read the TLV at the current position. If this succeeds, return true and set the value argument to the short that is the V part of the TLV, and move the position to the byte beyond the current TLV.

C#
public bool TryReadInt16(out short value, int expectedTag, bool bigEndian = true)

Parameters

Type Name Description
short value

The output parameter where the value will be deposited.

int expectedTag

The tag that should be at the current position.

bool bigEndian

Specifies whether the result should be returned as big endian (true or no argument given) or little endian (false).

Returns

bool

A boolean, true if the read succeeds, false otherwise.

Remarks

This is the same as ReadInt16, except this method will not throw an exception if there is an error in reading, only return false. That is, if the expected tag is not found at the current position, or the length octets are not a valid encoding, or the value is not exactly two bytes, or there is not enough data in the buffer for the length given, this method will set value to 0 and will return false.

See the documentation for ReadInt16 for more information on what this method does.

Note that if there is a valid TLV with the expected tag, but the length is not 2, this method will return false.

In this article
Back to top Generated by DocFX