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

后端 未结 4 1951
抹茶落季
抹茶落季 2021-01-05 09:17

In this code:

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

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

is there a differenc

相关标签:
4条回答
  • 2021-01-05 09:53

    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

    0 讨论(0)
  • 2021-01-05 09:55

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

    0 讨论(0)
  • 2021-01-05 10:07

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

    .field private string[] files
    
    0 讨论(0)
  • 2021-01-05 10:14

    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 讨论(0)
提交回复
热议问题