It’s not something we do on a daily base so I write it here to be able to find it when I need it.
A colleague asked me a question on how to convert a VB function in C#, this function calculates the checksum for a string that has then to be sent through a serial port.
The problem was that VB converts a string “&HF6” to a short while my short.TryParse( “0xF6”, out val) don’t.
The problem is determined by the fact that as a default TryParse expects to receive a number and an Hexadecimal virtually isnt.
The solution is use the following:
val = Int16.Parse("0xF6", System.Globalization.NumberStyles.HexNumber);
Very easy, but it needed about half an hour finding and trying it, so I hope to help someone else spare that time 