2种方式初始化,有什么区别? [英] 2 ways to initialize, what's the difference?

查看:64
本文介绍了2种方式初始化,有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这两行之间有什么区别?


Dim args As Object()= New Object(){strText}

Dim args As Object ()= {strText}


args似乎也可以使用,比如说:


Me.Invoke(delegate,args)


Zytan

解决方案

2月16日下午2:38,Zytan < zytanlith ... @ yahoo.comwrote:


这两行之间有什么区别?


Dim args As Object()= New Object(){strText}

Dim args As Object()= {strText}


args似乎可用于任何一个,比方说,像这样:


Me.Invoke(代表,args)


Zytan



没有区别。


-

Tom Shelton


有趣。两个都有效的另一个缺点。


括号用于填充数组,因此对于表格来说,表示

''Dim args As Object( )= {strText}'',编译器第二次猜到你并且

假设你实际意味着''Dim args As Object()= New Object(){strText}''。


如果你编译以下内容并看看结果与Lutz

Roeder''s Relector你会发现两种形式的语句都会发出

相同的IL。


公共类Form1


私人strText字符串


私有子Button1_Click(ByVal sender As Object,ByVal e As EventArgs)

处理Button1.Click


Dim args As Object()= New Object(){strText}


End Sub


Private Sub Button2_Click(ByVal sender As Object,ByVal e As EventArgs)

处理Button2点击


Dim args As Object()= {strText}


End Sub


结束班级

Zytan < zy ********** @ yahoo.comwrote in message

news:11 ******************** **@a75g2000cwd.googlegr oups.com ...


这两行之间有什么区别?


Dim args As Object()= New Object(){strText}

Dim args As Object()= {strText}


args似乎可用于任何一个,比如说,像这样:


Me.Invoke(代表,args)

Zytan


" Zytan" < zy ********** @ yahoo.comschrieb:


这两行之间有什么区别?

Dim args As Object()= New Object(){strText}

Dim args As Object()= {strText}



没有区别(除了我会写''Dim Args()As Object = {strText}''

;-))。


-

MS Herfried K. Wagner

MVP< URL:http://dotnet.mvps.org/>

VB< URL:http://dotnet.mvps.org/dotnet/faqs/>


What is the difference between these two lines?

Dim args As Object() = New Object() {strText}
Dim args As Object() = {strText}

args seems usuable from either, say, like so:

Me.Invoke(delegate, args)

Zytan

解决方案

On Feb 16, 2:38 pm, "Zytan" <zytanlith...@yahoo.comwrote:

What is the difference between these two lines?

Dim args As Object() = New Object() {strText}
Dim args As Object() = {strText}

args seems usuable from either, say, like so:

Me.Invoke(delegate, args)

Zytan

There is no difference.

--
Tom Shelton


Interesting. Another foible where both are valid.

The brackets are used to populate an array so it appears that, for the form
''Dim args As Object() = {strText}'', the compiler second guesses you and
assumes you actually mean ''Dim args As Object() = New Object() {strText}''.

If you compile the following and have a look at the result with Lutz
Roeder''s Relector you will find that both forms of the statement emit
identical IL.

Public Class Form1

Private strText As String

Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
Handles Button1.Click

Dim args As Object() = New Object() {strText}

End Sub

Private Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs)
Handles Button2.Click

Dim args As Object() = {strText}

End Sub

End Class
"Zytan" <zy**********@yahoo.comwrote in message
news:11**********************@a75g2000cwd.googlegr oups.com...

What is the difference between these two lines?

Dim args As Object() = New Object() {strText}
Dim args As Object() = {strText}

args seems usuable from either, say, like so:

Me.Invoke(delegate, args)

Zytan


"Zytan" <zy**********@yahoo.comschrieb:

What is the difference between these two lines?

Dim args As Object() = New Object() {strText}
Dim args As Object() = {strText}

No difference (except that I''d write ''Dim Args() As Object = {strText}''
;-)).

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>


这篇关于2种方式初始化,有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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