String vs. string vs. Uri ?

M

Marcel Müller

Huh? System.String is a completely different type from System.Uri.
System.String doesn't know anything about how URIs work. System.Uri does.
Conversely System.Uri doesn't have all of the same string-manipulation
features that the System.String class does.

If you're dealing with general-purpose strings of text, then you use
System.String. If you're dealing with URIs, then you use System.Uri.

I would add:
If you're dealing with /components/ of URIs, then you use System.Uri.


Marcel
 
A

Arne Vajhøj


I will assume that the context is that you have
a method where there are 2 overloads - one taking
a string and one taking a URI - otherwise the
question does not make much sense.

As documented then the URL constructor do throw
exceptions in case of bad format.

I would also expect the method that takes a string
to convert it to a URI inside the method.

Which on you should use will depend on the context.

If you just have a string, then the code is simpler and easier
to read if you just pass that on and let the method convert
to URI.

If you already have a URI because you have been inspecting
or manipulating some parts of the URI, then pass that on.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top