Sunday, March 25, 2012

F# ≥ C# (ASCII string definition)

When go over the data definition in F#, I found the string ASCII definition in F# which was new to me. The ASCII string uses "B" as suffix and it represent an ASCII string and internally it is a byte[].
let asciiString = "abc"B;
In the C#, I have to do

string value = "abc";
// Convert the string into a byte[]. 
byte[] asciiBytes = Encoding.ASCII.GetBytes(value);

This small syntax sugar would help me a lot when I did some programming targeting to PLC and other hardware.


No comments: