Monday, March 4, 2013

C# V/S VB.Net - Difference in Literals

Recently I was going through C# code which I needed to port to VB.Net. Usually I take help of reflector to do these kind of tasks. ie Opens the dll in reflector and change the language, export the project. But since this piece of code is small, I thought of trying manually

It was all going smooth since I encounter the below line

return 3e3m;

I could understand that this suffix 'm' is a decimal literal by placing the mouse over the number.Thanks to Visual Studio. But how to convert this to VB.Net. Initially I tried copy pasting the same string. No chance. So as usual had to google. There is no direct comparison of literals even in wiki page which explains the difference between C# and VB.Net. The literal to denote decimal in VB.Net is 'D'. There are so many literals like 'm' in C# such as D for double,  f for float etc...which are not same in VB.Net.

char '' ('a') ""c ("a"c)
Int I (100I) I / % (100%)
Unsigned Int U / u (100U) UI (100UI)
Long L / l (-100L) L / & (-100&)
Unsigned Long UL / ul (100UL) UI (100UL)
float / Single F / f (102.2F) F / ! (102.2!)
double D / d (102.2D) R / # (102.2#)
decimal M / m ( 202.3M) D /@ (202.3D)
exponent E / e (2E3M decimal 2000) Replaced with value in editor
xml literals Not available  Direct xml string

Below are the links to literals in C# and VB.Net .



No comments: