What is the purpose of the Uri class?

Asked

Viewed 947 times

6

What is the class Uri and what is its purpose and where it should be used?

Cannot pass an object from it to a string variable see in the example:

String caminho = new Uri(@"c:\Windows");

Generates the following error:

Error 1 Cannot implicitly Convert type 'System.Uri' to 'string'

I read about which is used in strings, but I’m confused by that.

  • 1

    If not using class functionality Uri, it makes no sense to think about using it: rtfm

1 answer

10


I already answered what is URI.

At the bottom is a canonical "address" of a resource. And uses where you need an address like this. If you need a web page address, a file path, a reference that has a pattern of where you are and what that is.

Obviously it has a format and rules of what it can have there.

Is not used in strings. It is possible to obtain a string generated with the contents of a URI, as well as creating a URI trying to parse one string.

The syntax is clearly incorrect. You are creating an object of the type Uri and trying to keep in a kind String, does not give. In these cases a var is usually the best option.

To documentation maybe help something.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.