变量名称的大小写 [英] Case for variable names

查看:94
本文介绍了变量名称的大小写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以为我读过变量名称的情况很重要。


例如


Dim Wheel As Integer


这里的轮子是与WHEEL不同的变量。


这是正确的吗?


它没有''似乎在我的代码中。在我的代码中,我正在多次更换WHEEL(只需

进行测试)并显示Wheel。轮子总是正确的。

我会认为Wheel会是0,因为我只改变了

WHEEL - 如果情况很重要的话。

另外,如果你定义一个变量,它是否会被初始化?



" Dim Wheel As Integer" ;初始化为0并且Dim firstName As String

初始化为"


谢谢,


Tom

I thought I read that the case for the variable names is important.

For example

Dim Wheel As Integer

Wheel here is a different variable from WHEEL.

Is this correct?

It doesn''t seem to be in my code. In my code, I am changing WHEEL (just
for testing)many times and displaying Wheel. Wheel is always correct.
I would have assumed that Wheel would have been 0, since I only changed
WHEEL - if case is important.

Also, if you define a variable, does it get initialized?

For example

"Dim Wheel As Integer" is initialized to 0 and "Dim firstName As String"
is initialized to "".

Thanks,

Tom

推荐答案

Thomas,
我以为我读过变量的情况名字很重要。
VB.NET不区分大小写:一个例程中的wheel,wheel和WHEEL都是

所有相同的标识符。


C#区分大小写:一个例程中的车轮,车轮和车轮都是唯一的

标识符。

Dim Wheel As Integer
这里的车轮与车轮的变量不同。
是这个对吗?
No.

另外,如果你定义一个变量,它是否会被初始化?
是的,带有默认值对于那种类型。

Dim Wheel As Integer初始化为0
更正默认 Integer的值是0.

和Dim firstName As String被初始化为。
不正确,String是引用类型,引用的默认值

类型,包括字符串,是Nothing。然而,VB.NET处理的字符串是

与"无关。在多数情况下。然而,当它的Nothing将失败时,调用一个实际的方法

firstName!


Dim firstName As String

Debug.WriteLine(firstName .Length())


会导致NullReferenceException,因为firstName包含Nothing。


但是,以下成功:


Dim firstName As String

Debug.WriteLine(firstName ="")

如果我想要或需要字符串变量来包含" ;,我将明确

用"初始化它们。或者String.Empty。


Dim firstName As String =""


希望这会有所帮助

Jay


" Thomas Scheiderich" < tf*@deltanet.com>在消息中写道

news:40 ************** @ deltanet.com ...我以为我读过变量名称的情况很重要。

例如

Dim Wheel As Integer

这里的轮子是与WHEEL不同的变量。

这是正确的吗?

它似乎不在我的代码中。在我的代码中,我正在多次更换WHEEL(仅用于测试)并显示Wheel。轮子总是正确的。
我会认为Wheel会是0,因为我只改变了轮子 - 如果情况很重要的话。

另外,如果你定义一个变量,它是否被初始化?

例如

Dim Wheel As Integer被初始化为0并且Dim firstName As String
被初始化为"

谢谢,

Tom
I thought I read that the case for the variable names is important. VB.NET is case insensitive: Wheel, wheel and WHEEL within one routine are
all the same identifier.

C# is case sensitive: Wheel, wheel and WHEEL within one routine all unique
identifiers.
Dim Wheel As Integer
Wheel here is a different variable from WHEEL.
Is this correct? No.
Also, if you define a variable, does it get initialized? Yes with the "default value" for that type.
"Dim Wheel As Integer" is initialized to 0 Correct the "default" value for Integer is a 0.
and "Dim firstName As String" is initialized to "". Incorrect, String is a reference type, the default value for reference
types, including string, is Nothing. However VB.NET treats a string that is
Nothing the same as "" in most cases. However calling an actually method of
firstName when its Nothing will fail!

Dim firstName As String
Debug.WriteLine(firstName.Length())

Will cause a NullReferenceException, as firstName contains Nothing.

However, the following succeeds:

Dim firstName As String
Debug.WriteLine(firstName = "")
If I want or need string variables to contain "", I will explicitly
initialize them with "" or String.Empty.

Dim firstName As String = ""

Hope this helps
Jay

"Thomas Scheiderich" <tf*@deltanet.com> wrote in message
news:40**************@deltanet.com... I thought I read that the case for the variable names is important.

For example

Dim Wheel As Integer

Wheel here is a different variable from WHEEL.

Is this correct?

It doesn''t seem to be in my code. In my code, I am changing WHEEL (just
for testing)many times and displaying Wheel. Wheel is always correct.
I would have assumed that Wheel would have been 0, since I only changed
WHEEL - if case is important.

Also, if you define a variable, does it get initialized?

For example

"Dim Wheel As Integer" is initialized to 0 and "Dim firstName As String"
is initialized to "".

Thanks,

Tom


嗨Thomas,


我看到你忙于网页。
Hi Thomas,

I saw you are busy with webpages.
我以为我请注意,变量名称的大小写非常重要。
I thought I read that the case for the variable names is important.




不使用VB的语言(通过实例获取ado.net变量名称

之间的引用是这样的)


味道不同但是对于大多数使用VB的人来说VB是其他语言的重要优势,VB找到这个问题本身。


我希望这说清楚吗?


Cor



Not with the language from VB (By instance for the ado.net variable names
between quotes it is)

The taste is different but for most people who uses VB that is an important
advantage from VB on other languages, VB find the propercase itself.

I hope this makes it clear?

Cor


嗨Tom,


除了Jay,因为我看到你忙于网页。


J ++,Java, JavaScript,C ++,C#和C都是区分大小写的。

(全部来自C派生语言)


Cor
Hi Tom,

In addition to Jay, because I saw you are busy with Webpages.

J++, Java, JavaScript, C++, C# and C are all case sensitive.
(It are all from C derived languages)

Cor


这篇关于变量名称的大小写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆