Exclamation(!) operator used on a number in vb.net

2020-07-06 04:59发布

问题:

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.

回答1:

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.



回答2:

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)



回答3:

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.



标签: vb.net