What does a percentage symbol mean as part of a va

2019-01-26 06:47发布

问题:

I'm just looking at some VB.NET code and I came across this:

Dim var%

Later var is set to 0.

What's the purpose of the percent sign (%)?

(Google and SO search failed me)

回答1:

Dim varname% is ancient BASIC syntax for "varname is an integer". This has been around for a very long time in the history of the BASIC family, and is supported in Visual Basic.NET (although I, personally, wouldn't recommend it - it can be rather opaque, as discovered by you).



回答2:

It is shorthand for declaring "var" as of Type Integer, and has roots in the early, early days of BASIC (yes...old-school DOS BASIC).

So this:

Dim var%

is equivalent to:

Dim var As Integer

Here is the actual MS documentation: https://support.microsoft.com/en-us/kb/191713

      %                 Integer
      &                 Long
      !                 Single
      #                 Double
      $                 String
      @                 Currency


回答3:

Putting a % sign at the end of the variable name in Visual Basic indicates that it is an integer. This was used by programmers in the old VB days, I am not sure why it is still present in VB.NET. Don't use it in new code, for all you know it might be gone in future versions of VB.NET.

& : Long

% : Integer

'# : Double

! : Single

@ : Decimal

$ : String