Kakoroat
Kakoroat

Reputation: 101

Exclamation(!) operator used on a number in vb.net, what does this do?

I'm looking at inherited code and I found this in a vb.net windows form:

New System.Drawing.SizeF(6.0!, 13.0!)

My question is, what is the significance of the ! (exclamation) operator here? Most of my searching for the exclamation operator ends up returning recordset format or the ! gets ignored in the search and I get hundreds of unrelated items.

Upvotes: 10

Views: 2980

Answers (3)

Oded
Oded

Reputation: 499072

In this case, the ! stands for Single:

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.

(emphasis mine)

Upvotes: 4

dbasnett
dbasnett

Reputation: 11773

It is a type character. It means that 6.0 is a Single data type.

http://msdn.microsoft.com/en-us/library/s9cz43ek.aspx show the type characters.

Upvotes: 3

Damien_The_Unbeliever
Damien_The_Unbeliever

Reputation: 239724

It's to force the literal to be a Single.

Visual Basic supports Type Characters:

In addition to specifying a data type in a declaration statement, you can force the data type of some programming elements with a type character. The type character must immediately follow the element, with no intervening characters of any kind.

and:

Literals can also use the identifier type characters (%, &, @, !, #, $), as can variables, constants, and expressions. However, the literal type characters (S, I, L, D, F, R, C) can be used only with literals.

Upvotes: 11

Related Questions