2

As covered well in this question, System.Uri is a good choice to reflect my intention for URIs. But what about for email addresses?

It seems not as clear-cut, because MailAddress has extra information in its DisplayName property that is not a great fit.

Community
  • 1
  • 1
Domenic
  • 110,262
  • 41
  • 219
  • 271
  • 1
    You don't have to use every bit of information provided by the MailAddress class. I would consider it pretty minimal overhead for the assurance of having well formed email addresses everywhere in your domain. – Quick Joe Smith Mar 13 '11 at 07:50

2 Answers2

5

You don't have to use the DisplayName if you don't want or need to. The MailAddress type ensures that an email address is well formed by throwing an exception in it's constructor otherwise. I would argue that it is worth using MailAddress over String for this reason and also because it communicates intent and adds little overhead.

Adam Ralph
  • 29,453
  • 4
  • 60
  • 67
1

System.Uri has a lot of useful functionality, but System.Net.Mail.MailAddress doesn't, so whether to use it is not a critical decision. FWIW, I have implemented it both ways (but in different places!) -- string and MailAddress.

John Pick
  • 5,562
  • 31
  • 31