Reputation: 112857
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.
Upvotes: 2
Views: 203
Reputation: 29956
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.
Upvotes: 5
Reputation: 5650
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.
Upvotes: 1