Exclamation point (!) in VB.NET

The following code is designer generated:

Me.lblXRay.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))

What does 8.0! mean?

Upvotes: 12

Views: 6023

Answers (4)

Fredou
Fredou

Reputation: 20120

It means type Single. See Single Data Type (Visual Basic) (under section Programming Tips).

Upvotes: 7

Gerhard Powell
Gerhard Powell

Reputation: 6175

****Here is a Cheat Sheet for DataTypes ****

Variable End with:

$ : String
% : Integer (Int16)
& : Long (Int32)
! : Single
# : Double
@ : Decimal

Start with:

&H : Hex
&O : Octal

Comparison between VB and VB.Net (reference)

Visual Studio .Net added Literal Types (reference)

Value End with: (For more complete list, refer the the reference)

S : Short (Int16)
I : Integer (Int32)
L : Long (Int64)
F : Single
R : Double
D : Decimal

Upvotes: 2

Mark Hall
Mark Hall

Reputation: 54542

From the MSDN library:

Type Characters. Appending the literal type character F to a literal forces it to the Single data type. Appending the identifier type character ! to any identifier forces it to Single.

Upvotes: 5

Hans Passant
Hans Passant

Reputation: 941873

This dates back to very early versions of Microsoft Basic. These type characters let you both set the type of an identifier and a literal:

    Dim singleVar! = 1.2!
    Dim doubleVar# = 1.2#
    Dim decimalVar@ = 1.2@
    Dim integerVar% = 12%
    Dim longVar& = 12&
    Dim stringVar$ = "12"

    Function ReturnsString$(ByVal takesLong&)

Upvotes: 16

Related Questions