Frage

How to convert an UInt16 valu to a byte array of size 2

I found some code in MSDN but I am not sure if it is ok to use in my case:

// Convert a ushort argument to a byte array and display it. 
public static void GetBytesUInt16( ushort argument )
{
    byte[ ] byteArray = BitConverter.GetBytes( argument );
    Console.WriteLine( formatter, argument, 
        BitConverter.ToString( byteArray ) );
}

What I have is UInt16 ... is it ok to just cast it to ushort and use the code above?!

War es hilfreich?

Lösung

UInt16 and ushort are the same datatypes so yes

http://msdn.microsoft.com/en-us/library/cbf1574z(v=vs.80).aspx

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top