O'Reilly logo

C# 5.0 Unleashed by Bart De Smet

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required