谁能告诉我为什么要执行此操作
Module Module1
Sub Main()
Dim currentSourceData As New SourceData
currentSourceData.datafiles.Add("234")
End Sub
End Module
给我
System.NullReferenceException:'对象引用未设置为对象的实例。'
当我使用自动实施的功能
Public Class SourceData
Public Property datafiles() As List(Of String)
End Class
但是当我使用完全写好的属性时,却没有:
Public Class SourceData
Private _datafiles As New List(Of String)
Public Property datafiles() As List(Of String)
Get
Return _datafiles
End Get
Set(value As List(Of String))
_datafiles = value
End Set
End Property
End Class
答案 0 :(得分:2)
New
运算符在此处缺失:
Public Class SourceData
Public Property datafiles() As List(Of String)
End Class