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 ...

Get C# 5.0 Unleashed now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.