我是自定义类的新手。这是我的类定义:
Public Class game
Private strName As String()
Property name As String()
Get
Return strName
End Get
Set(ByVal Value As String())
strName = Value
End Set
End Property
End Class
这是我从文件中读取并创建“游戏”实例的代码
Public Sub loadGames()
Dim game As New game
Dim dir As New IO.DirectoryInfo(gameFolder)
Dim fs As IO.FileInfo() = dir.GetFiles("*.gemui")
Dim f As IO.FileInfo
For Each f In fs
Dim path As String = f.FullName
Dim fi As New FileInfo(path)
Dim sr As StreamReader = fi.OpenText()
Dim s As String = ""
While sr.EndOfStream = False
game.name = sr.ReadLine() '"Value of type 'String' cannot be converted to '1-dimensional array of String'."
MsgBox(sr.ReadLine()) 'shows a message box with exactly what I expect to see
End While
sr.Close()
Next
End Sub
game.name = sr.ReadLine()是问题所在。 “‘字符串’类型的值不能转换为‘字符串的一维数组’。”