The Uri Type
In the world of massively connected systems, addressing of endpoints is quite common, so it makes sense to have a built-in primitive for uniform resource identifiers (URIs). The
Uri class provided for this purpose supports both absolute and relative URIs and has a bunch of properties to query the various parts of a URI. A basic example is shown here:
var url = new Uri("http://bar:8080/foo/quz?answer=42");Console.WriteLine(url.Host); // barConsole.WriteLine(url.Port); // 8080Console.WriteLine(url.AbsolutePath); // /foo/quzConsole.WriteLine(url.Query); // ?answer=42
Lots of complexities exist with regard to escaping, security of hostnames, and so forth. This is one of the reasons ...