Code in one line

  • Thread starter Thread starter shapper
  • Start date Start date
S

shapper

Hello,

I have created an email message:
Dim email As New System.Net.Mail.MailMessage

Is it possible to make the following code in one code line (here ***):

Dim emailCollection As New System.Net.Mail.MailAddressCollection
Dim emailAddress As Net.Mail.MailAddress

emailAddress = New Net.Mail.MailAddress("sd", "sd")
emailCollection.Add(emailAddress)
email.To = emailCollection ***

Thanks,
Miguel
 
I now reduced to less lines:

Dim emailCollection As New System.Net.Mail.MailAddressCollection

emailCollection.Add(New Net.Mail.MailAddress("sd", "sd") )
email.To = emailCollection

I also tried the following:

email.To = New System.Net.Mail.MailAddressCollection.Add(New
Net.Mail.MailAddress("sd", "sd") )

This is what I was trying to no but no success.

Thanks,

Miguel
 
2 lines is probably the shortest you can make it (untested code alert):

email.To = New System.Net.Mail.MailAddressCollection()
CType(email.To, System.Net.Mail.MailAddressCollection).Add(New
Net.Mail.MailAddress("sd", "sd") )


But I think its better to keep it as 4 or 5 because it is much more
readable.
Getting it down to 1 line is kind of pointless. Maintainability is much
more important than any slight performance benefit you *might* get.

Steven
 
Back
Top