Expert Texture Home Contact me About Subscribe Digipede Connect on LinkedIn rwandering on Twitter rwandering on FriendFeed

The blogged wandering of Robert W. Anderson

System.Uri.Equals(…) What?

Can someone explain why the following expression evaluates to true?  There must be some historical perspective that I’m just missing.

new Uri("") == new Uri("")

I would understand:

  1. A use case for a separate Uri.Compare method giving the caller control over which components should be compared;
  2. 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: , , ,



    Dan Ciruli wrote @ August 8th, 2007 at 8:03 pm

Did you mean those to be identical?

    Robert W. Anderson wrote @ August 8th, 2007 at 8:26 pm

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.

    Dan Ciruli wrote @ August 8th, 2007 at 8:59 pm

Oh, because before I was pretty sure why that might evaluate to true.

Now, I’m as confused as you.

    Shannon Whitley wrote @ August 9th, 2007 at 1:05 pm

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?

    Robert W. Anderson wrote @ August 13th, 2007 at 2:10 pm

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.

Your comment

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>