What's different between Dim files() As String and Dim files As String()?
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
精彩评论