rwandering.net
The blogged wandering of Robert W. Anderson
August 8, 2007 at 4:03 pm
· Filed under .NET
Can someone explain why the following expression evaluates to true? There must be some historical perspective that I’m just missing.
new Uri("mailto:somebody@example.com") == new Uri("mailto:somebodyelse@example.com")
I would understand:
- A use case for a separate Uri.Compare method giving the caller control over which components should be compared;
- If Uri.Equals performed its comparison against canonicalized URIs.
The docs say that the user info, fragment, and (in older .NETs) query are all ignored for comparison. There is no mention for the email address in a mailto; however.
What? Why?
Tags: .NET, BCL, c#, Microsoft
Permalink
Trackback
Did you mean those to be identical?
Thanks, Dan. Arg. I mean Argh. Haven’t blogged in a month and now I’m 0 for 2. I’ve corrected the post — LiveWriter kept “smartly” converting my code into link tags — I must have messed up while undoing that.
Oh, because before I was pretty sure why that might evaluate to true.
Now, I’m as confused as you.
I might be totally off on this, but is the comparison being done at the object-type level? Perhaps it’s using the ToString() method for the comparison. In either case, they would both be [System.Uri]. Maybe you have to use the AbsoluteUri property to perform a valid comparison?
Shannon — I think you saw the original problem post — as it was, you are right they correclty compared to the same value, though not the same object.
HTML-Tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>