Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
User info in
Previously, Uri didn't compare user info when comparing two Uri
instances for equality. However, this behavior is not intuitive in the case of mailto:
URIs. With this change, Uri.Equals and the ==
operator now consider user info when comparing URIs.
Previous behavior
Prior to .NET 8, both of the following comparisons returned true
.
Uri uri1 = new Uri("https://[email protected]");
Uri uri2 = new Uri("https://[email protected]");
System.Console.WriteLine(uri1 == uri2); // True.
Uri uri3 = new Uri("mailto:[email protected]");
Uri uri4 = new Uri("mailto:[email protected]");
System.Console.WriteLine(uri3 == uri4); // True.
New behavior
Starting in .NET 8, the first comparison still returns true
, but the second comparison (of mailto
URIs) returns false
.
Uri uri1 = new Uri("https://[email protected]");
Uri uri2 = new Uri("https://[email protected]");
System.Console.WriteLine(uri1 == uri2); // True.
Uri uri3 = new Uri("mailto:[email protected]");
Uri uri4 = new Uri("mailto:[email protected]");
System.Console.WriteLine(uri3 == uri4); // False.
Version introduced
.NET 8
Type of breaking change
This change is a behavioral change.
Reason for change
The previous behavior was unexpected and unintuitive.
Recommended action
If you want to compare only the host part of email addresses, compare only the Uri.Host members.