Eugene D. Gubenkov Eugene D. Gubenkov - 6 months ago 40
C# Question

.NET Uri.ToString() ruins the URL?

I've noticed that if you call

when URI behind is URL with percent encoded spaces (%20), then you will have malformed URL as the result:

// result: " segment"
new Uri("").ToString();

Since URL is URI (opposite statement is not correct) and URL with non encoded spaces is not valid it looks like it's not safe to use Uri as the container for URL.

Is it correct behaviour?


As per MSDN:

// result: " segment"
new Uri("").ToString();

// result: ""
new Uri("").OriginalString;