tabs ↹ over ␣ ␣ ␣ spaces

by Jiří {x2} Činčura

MailAddress class is driving me crazy

14 May 2013 .NET, Best practice or not?, Email

I’m now working a lot with emails and email addresses. Loading, parsing and so on. Because of that I’m also using a MailAddress class a lot. And I hate it. The class, even simple, makes me want to scream.

Consider simple code like this.

var mail1 = new MailAddress("mail@example.com");
var mail2 = new MailAddress("MAIL@example.com");
Console.WriteLine("Equals?:\t{0}", mail1.Equals(mail2));
Console.WriteLine("Equals?:\t{0}", mail2.Equals(mail1));
Console.WriteLine("GetHashCode1:\t{0}", mail1.GetHashCode());
Console.WriteLine("GetHashCode2:\t{0}", mail2.GetHashCode());

What do you think the output be? Drum roll please…

Equals?:        True
Equals?:        True
GetHashCode1:   582340455
GetHashCode2:   1045083261

Why the hell somebody did the work overriding the Equals and not providing the implementation of GetHashCode that aligns with that?

I think it’s time to implement my own. 8-)