我正在尝试将行添加到具有公共字段的公共类中并且出现错误:对象引用未设置为对象的实例
Public Class EmailRecipient
EmailAddress As String = ""
FullName As String = ""
End Class
Public Class EmailDetails
Public FromEmail As String = ""
Public ToEmails As List(Of Emails) = nothing
End Class
Public Sub SetEmailDetails
'Populate EmailRecipient Class
Dim er As New EmailRecipient
er.EmailAddress = "rodney@norespect.com"
er.FullName = "Rodney Dangerfield"
'Populate EmailDetails Class
Dim ed As New EmailDetails
ed.FromEmail = "sender@danger.com" 'This works fine
ed.ToEmails.Add(er) 'Here error happens
End Sub
我猜我需要先创建一个 EmailRecipient 类的实例,然后才能向其中添加项目。
不知道如何使用公共类中的公共字段来做到这一点?
这是艰难的一天。我今天早上起床,穿上一件衬衫,一个纽扣掉了下来。我拿起公文包,把手掉了。我害怕去洗手间。
谢谢您的帮助 :-)