昏暗的差异 [英] dim differences

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

问题描述

您好


有人会告诉我以下陈述之间的区别吗?当

你会使用一个吗?


dim objtest1 as car

dim objtest2 as new car

dim objtest3 as car = new car


是不是objtest2和objtest3做同样的事情?我理解=

变量声明后设置初始值但想澄清。

:)


谢谢。

Hello

Would someone tell me the differences between following statements? When
would you use one over the other?

dim objtest1 as car
dim objtest2 as new car
dim objtest3 as car = new car

Are not objtest2 and objtest3 doing the same thing? I understand the =
after variable declaration sets initial value but would like clarification.
:)

thanks.

推荐答案

RdS,

|有人会告诉我以下陈述之间的区别吗?

| dim objtest1 as car

假设Car是一个参考类型。定义一个可以保存Car

对象的变量,但是没有创建Car对象。


|昏暗的objtest2作为新车

| dim objtest3 as car = new car

定义可以保存Car对象的变量,用新的Car对象初始化那些变量



|你什么时候用另一个?

| dim objtest1 as car

|昏暗的objtest2作为新车

当Car对象来自其他地方时我会使用第一个

(例如For Each中的控制变量,或者返回值来自

函数)。

|是不是objtest2和objtest3做同样的事情?我理解=

|在变量声明之后设置初始值但是希望

澄清。

是的,它们是相同的,


| dim objtest3 as car = new car

我可以在创建派生类时使用它,但请确保我只使用基类方法使用
。 />

Dim s As Stream =新FileStream(...)

但是通常新FileStream实际上是隐藏在工厂方法中

某个地方...


-

希望这会有所帮助

Jay B. Harlow [MVP - Outlook]

..NET应用程序架构师,爱好者,&福音传教士

T.S.布拉德利 - http://www.tsbradley.net

" ; RDS" < rd*@nospam.nospamwrote in message

news:eH ************** @ TK2MSFTNGP03.phx.gbl ...

|您好

|

|有人会告诉我以下陈述之间的区别吗?当

|你会用另一个吗?

|

| dim objtest1 as car

|昏暗的objtest2作为新车

| dim objtest3 as car = new car

|

|是不是objtest2和objtest3做同样的事情?我理解=

|变量声明后设置初始值,但希望

澄清。

| :)

|

|谢谢。

|

|
RdS,
| Would someone tell me the differences between following statements?
| dim objtest1 as car
Assuming Car is a reference type. Defines a variable that can hold a Car
object, however no Car object is created.

| dim objtest2 as new car
| dim objtest3 as car = new car
Defines variables that can hold Car objects, initializes those variables
with new Car objects.
| When would you use one over the other?
| dim objtest1 as car
| dim objtest2 as new car
I would use the first when the Car object was coming from someplace else
(such as the control variable in a For Each, or the return value from a
function).
| Are not objtest2 and objtest3 doing the same thing? I understand the =
| after variable declaration sets initial value but would like
clarification.
Yes they are the same thing,

| dim objtest3 as car = new car
I use it when I may create a derived class, but be certain that I''m only
using base class methods.

Dim s As Stream = New FileStream(...)

However generally the New FileStream is actually hidden in a factory method
someplace...

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"RdS" <rd*@nospam.nospamwrote in message
news:eH**************@TK2MSFTNGP03.phx.gbl...
| Hello
|
| Would someone tell me the differences between following statements? When
| would you use one over the other?
|
| dim objtest1 as car
| dim objtest2 as new car
| dim objtest3 as car = new car
|
| Are not objtest2 and objtest3 doing the same thing? I understand the =
| after variable declaration sets initial value but would like
clarification.
| :)
|
| thanks.
|
|


是的。确实如此。


关于
的最后一个问题
Yes. It did.

One final question about

|昏暗的objtest2作为新车

| dim objtest3 as car = new car

定义可以保存Car对象的变量,使用新的Car对象初始化这些变量


| dim objtest2 as new car
| dim objtest3 as car = new car
Defines variables that can hold Car objects, initializes those variables
with new Car objects.



为什么不总是使用昏暗的objtest2作为新车?第二个需要更多

打字等等。有没有理由不总是使用第一个声明。

我问的原因是因为在同一作者的某些代码中相同的装配我

找到两者的用途。这只是偏好还是他们的理由?


再次感谢。

Jay B. Harlow [MVP - Outlook]" < Ja ************ @ tsbradley.netwrote在

消息新闻:u9 ************** @ TK2MSFTNGP06.phx .gbl ...

Why not always use dim objtest2 as new car? The second requires more
typing, etc. Is there any reason why not always to use the first statement.
The reason I ask is because in some code by same author in same assembly I
find the use of both. Is this just preference or was their a reason?

Thanks again.
"Jay B. Harlow [MVP - Outlook]" <Ja************@tsbradley.netwrote in
message news:u9**************@TK2MSFTNGP06.phx.gbl...


RdS,

|有人会告诉我以下陈述之间的区别吗?

| dim objtest1 as car

假设Car是一个参考类型。定义一个可以保存Car

对象的变量,但是没有创建Car对象。


|昏暗的objtest2作为新车

| dim objtest3 as car = new car

定义可以保存Car对象的变量,用新的Car对象初始化那些变量




|你什么时候用另一个?

| dim objtest1 as car

|昏暗的objtest2作为新车

当Car对象来自其他地方时我会使用第一个

(例如For Each中的控制变量,或者返回值来自

函数)。


|是不是objtest2和objtest3做同样的事情?我理解=

|在变量声明之后设置初始值但是希望

澄清。

是的,它们是相同的,


| dim objtest3 as car = new car

我可以在创建派生类时使用它,但请确保我只使用基类方法使用
。 />

Dim s As Stream =新FileStream(...)

但是通常New FileStream实际上隐藏在工厂中

方法

某处...


-

希望这有帮助

Jay B. Harlow [MVP - Outlook]

.NET Application Architect,Enthusiast,&福音传教士

T.S.布拉德利 - http://www.tsbradley.net


" RdS" < rd*@nospam.nospamwrote in message

news:eH ************** @ TK2MSFTNGP03.phx.gbl ...

|您好

|

|有人会告诉我以下陈述之间的区别吗?



|你会用另一个吗?

|

| dim objtest1 as car

|昏暗的objtest2作为新车

| dim objtest3 as car = new car

|

|是不是objtest2和objtest3做同样的事情?我理解=

|变量声明后设置初始值,但希望

澄清。

| :)

|

|谢谢。

|

|

RdS,
| Would someone tell me the differences between following statements?
| dim objtest1 as car
Assuming Car is a reference type. Defines a variable that can hold a Car
object, however no Car object is created.

| dim objtest2 as new car
| dim objtest3 as car = new car
Defines variables that can hold Car objects, initializes those variables
with new Car objects.
| When would you use one over the other?
| dim objtest1 as car
| dim objtest2 as new car
I would use the first when the Car object was coming from someplace else
(such as the control variable in a For Each, or the return value from a
function).
| Are not objtest2 and objtest3 doing the same thing? I understand the =
| after variable declaration sets initial value but would like
clarification.
Yes they are the same thing,

| dim objtest3 as car = new car
I use it when I may create a derived class, but be certain that I''m only
using base class methods.

Dim s As Stream = New FileStream(...)

However generally the New FileStream is actually hidden in a factory
method
someplace...

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
.NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"RdS" <rd*@nospam.nospamwrote in message
news:eH**************@TK2MSFTNGP03.phx.gbl...
| Hello
|
| Would someone tell me the differences between following statements?
When
| would you use one over the other?
|
| dim objtest1 as car
| dim objtest2 as new car
| dim objtest3 as car = new car
|
| Are not objtest2 and objtest3 doing the same thing? I understand the =
| after variable declaration sets initial value but would like
clarification.
| :)
|
| thanks.
|
|



Hello RdS,


对于你提到的新问题


===================
Hello RdS,

For the new question you mentioned

===================

|昏暗的objtest2作为新车

| dim objtest3 as car = new car

定义可以保存Car对象的变量,使用新的Car对象初始化这些变量


| dim objtest2 as new car
| dim objtest3 as car = new car
Defines variables that can hold Car objects, initializes those variables
with new Car objects.



为什么不总是使用昏暗的objtest2作为新车?第二个需要更多

打字等等。

===================

我认为这只是个人偏好,对此没有严格的要求或最佳做法。对于VB程序员来说,第一个将
保存更多单词。并且有一些c#或其他程序员可能会优先选择第二个,因为他们习惯于首先声明变量

并通过=分配初始值;。 :-)


如果您有任何疑问,请随时在此发布。


此致,


Steven Cheng


Microsoft MSDN在线支持主管

此帖子按原样提供。没有保证,也没有授予任何权利。

Why not always use dim objtest2 as new car? The second requires more
typing, etc.
===================

I think it is just a personal preference and there is no critical
requirement or best practice on this. For VB programmers, the first will
save more words. And there are some c# or other programmers which may
prefer the second one because they''re accustomed to declare the variable
first and assign initial value through "=". :-)

Please feel free to post here if there is anything else you''re wondering.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.


这篇关于昏暗的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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