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



Question:

In this code:

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

is there a difference between the statements?


Solution:1

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

.field private string[] files  


Solution:2

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


Solution:3

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


Solution:4

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  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »