vb.net 百分比符号作为变量名称的一部分是什么意思?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16454621/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What does a percentage symbol mean as part of a variable name?
提问by Rowan Freeman
I'm just looking at some VB.NET code and I came across this:
我只是在看一些 VB.NET 代码,我发现了这个:
Dim var%
Later varis set to 0.
后来var设置为0。
What's the purpose of the percent sign (%)?
百分号 ( %)的用途是什么?
(Google and SO search failed me)
(谷歌和 SO 搜索失败了我)
回答by michaelb958--GoFundMonica
Dim varname%is ancient BASIC syntax for "varnameis 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).
Dim varname%是“varname是整数”的古老 BASIC 语法。这在 BASIC 系列的历史上已经存在很长时间了,并且在 Visual Basic.NET 中得到支持(尽管我个人不推荐它 - 正如您所发现的那样,它可能相当不透明)。
回答by Idle_Mind
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).
它是将“var”声明为整数类型的简写,并且起源于 BASIC 的早期(是的......老派 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
这是实际的 MS 文档:https: //support.microsoft.com/en-us/kb/191713
% Integer
& Long
! Single
# Double
$ String
@ Currency
回答by Gary
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.
在 Visual Basic 中在变量名的末尾放置一个 % 符号表示它是一个整数。这是程序员在旧 VB 时代使用的,我不确定为什么它仍然存在于 VB.NET 中。不要在新代码中使用它,因为你知道它可能会在 VB.NET 的未来版本中消失。
& : Long
& : 长
% : Integer
% : 整数
'# : Double
'# : 双倍的
! : Single
!: 单身的
@ : Decimal
@:十进制
$ : String
$ : 字符串

