开发者

What's different between Dim files() As String and Dim files As String()?

开发者 https://www.devze.com 2022-12-20 00:49 出处:网络
In this code: Dim files() As String = Directory.GetFiles(\"C:/\") Dim files As String() = Directory.GetFiles(\"C:开发者_如何学编程/\")

In this code:

Dim files() As String = Directory.GetFiles("C:/")

Dim files As String() = Directory.GetFiles("C:开发者_如何学编程/")

is there a difference between the statements?


The two are identical. If you use Reflector, you can see that they are compiled to the same IL:

.field private string[] files


They produce exactly the same thing - just two alternative forms of declaration.


Both are the same

Dim files() As String = Directory.GetFiles("C:/")

Dim files As String() = Directory.GetFiles("C:/")

Both will declare an array and store all files name in C:\ directory


Actually, there is a difference. Example explains everything:

Class Demo
    Property X() As Byte
    Property Y As Byte()
End Class

...

Sub DemoCode()
    Dim d As New Demo()
    d.X = New Byte() {}   ' !!! invalid
    d.Y = New Byte() {}   ' valid
End Sub
0

精彩评论

暂无评论...
验证码 换一张
取 消