2

I'm hitting the following issue in this simple code:

Public Class BookStoreDatabase

Public publicationArray(0 To 3) As String

publicationArray(0) = "Stories to Scare People With"
End Class

The bit "publicationArray(0) etc" is telling me that a declaration for "publicationArray" is expected. This seems like it shouldn't be happening.

4

1 回答 1

2

您不能在Class级别分配数组元素。如果您需要在BookStoreDatabase类本身实例化后立即分配它,则必须使用构造函数:

Public Class BookStoreDatabase

    Public Sub New()
        publicationArray(0) = "Stories to Scare People With"
    End Sub

    Public publicationArray(0 To 3) As String

End Class
于 2014-03-14T17:43:00.403 回答