views:

1740

answers:

3

Just out of curiosity:

I know I can tell the compiler if I want a value to be interpreted as a certain numeric type, e.g. as Integer (32 bit signed) this way appending an "I" (type character) to the constant value:

Private Function GetTheAnswerAsInteger() As Integer

   Return 42I

End Function

There's also "S" for Short or "D" for Decimal etc.

But what is the suffix for Byte? Hint: it's not the obvious one "B"...

A: 

Byte doesn't require a suffix. EDIT: i.e There isn't one!

Mitch Wheat
Neither does Integer, but my question ist: IS THERE A SUFFIX - AND IF, WHAT'S THE LETTER?
splattne
That is what I meant!
Mitch Wheat
A: 

There's no byte literal in .NET.

arul
+5  A: 

There isn't one. If you need to distinguish between an integer and a byte (e.g. to call an appropriate overload) for a constant, you need to cast.

(The same is true in C#, by the way.)

MSDN provides confirmation:

Byte has no literal type character or identifier type character.

There's also a list of type characters and literal suffixes.

Jon Skeet
Little poor Byte, doesn't even have a literal type character... ;-)
splattne
For C# folks this section of the specification shows the various options. http://msdn.microsoft.com/en-us/library/aa664674%28VS.71%29.aspx
AverageAdam