title: How can I create a constructor that allows me to pass unassigned properties to a method without error?
body: <p>In the code below I pass several parameters to a method "<strong><em>SendEmail()</em></strong>".</p>
  
  <p>The unassigned String property <strong><em>myEmail.ToAddress.Name</em></strong> passes without issue, but when Class property <strong><em>myEmail.Bcc.Email</em></strong> gets passed without a value I get the "Object reference not set to an instance of an object" error.</p>
  
  <p>Can I modify my constructors to avoid this?</p>
  
  <p>Thanks.</p>
  
  <p><strong>Email Message Class</strong></p>
  
  <pre><code>Public Class EmailMessage
  
      Public Sub New()
  
          Dim ToAddress As New EmailAddress
          Dim FromAddress As New EmailAddress
          Dim Bcc As New EmailAddress
      End Sub
  
      Public Property ToAddress() As EmailAddress
          Get
              Return m_To
          End Get
          Set(value As EmailAddress)
              m_To = value
          End Set
      End Property
      Private m_To As EmailAddress
  
      Public Property FromAddress() As EmailAddress
          Get
              Return m_From
          End Get
          Set(value As EmailAddress)
              m_From = value
          End Set
      End Property
      Private m_From As EmailAddress
  
      Public Property Bcc() As EmailAddress
          Get
              Return m_Bcc
          End Get
          Set(value As EmailAddress)
              m_Bcc = value
          End Set
      End Property
      Private m_Bcc As EmailAddress
  
      Public Property Subject() As String
          Get
              Return m_Subject
          End Get
          Set(value As String)
              m_Subject = value
          End Set
      End Property
      Private m_Subject As String
  
      Public Property Body() As String
          Get
              Return m_Body
          End Get
          Set(value As String)
              m_Body = value
          End Set
      End Property
      Private m_Body As String
  
  End Class
  </code></pre>
  
  <p><strong>Email Address Class</strong></p>
  
  <pre><code>Public Class EmailAddress
  
      Public Sub New()
          Dim Email As String = ""
          Dim Name As String = ""
      End Sub
  
      Public Property Email() As String
          Get
              Return m_Email
          End Get
          Set(value As String)
              m_Email = value
          End Set
      End Property
      Private m_Email As String
  
      Public Property Name() As String
          Get
              Return m_Name
          End Get
          Set(value As String)
              m_Name = value
          End Set
      End Property
      Private m_Name As String
  End Class
  </code></pre>
  
  <p><strong>Code</strong></p>
  
  <pre><code>    Public Sub AssignVariables()
  
          Dim myEmail As New EmailMessage
          Dim toAddress As New EmailAddress
          Dim fromAddress As New EmailAddress
  
          toAddress.Email = "example@example.com"
          fromAddress.Email = "example@example.com"
  
          myEmail.ToAddress = toAddress
          myEmail.FromAddress = fromAddress
          myEmail.Subject = "Example"
          myEmail.Body = "Example"
  
          Call SendEmail(myEmail)
      End Sub
  
      Public Sub SendEmail(ByVal email As EmailMessage)
  
          Send SendEmail(email.FromAddress.Email, email.ToAddress.Name, email.ToAddress.Email, email.Bcc.Email, email.Subject, email.Body)
      End Sub
  
  
      Private Sub SendEmail(fromAddress As String, toName As String, toAddress As String, bcc As String, subject As String, body As String)
  
      End Sub
  </code></pre>