是否有任何理由使用的System.Uri? [英] Is there any reason to use System.Uri?

查看:179
本文介绍了是否有任何理由使用的System.Uri?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在找过来,它似乎是,这是从根本上打破了。

I'm looking it over and it seems to be that it is fundamentally broken.

  • 只有5实例方法不标记为已过时。
  • 虽然目前没有出现任何内置的方式来 分析查询字符串变量。
  • 有没有方法发生变异的URI,例如追加一个新的查询变量。
  • 在HttpUtility适用于字符串,而不是URI的
  • Only 5 instance methods aren't marked obsolete.
  • There doesn't appear to be any built-in way to parse query-string variables.
  • There are no methods to mutate the Uri, for example appending a new query variable.
  • HttpUtility works on strings, not URIs

那么,有没有什么是好?如果我真的可以用的只是字符串这个呢?

So is there anything it is good for? Should I really be using this instead of just strings?

推荐答案

我不会说Uri类是从根本上打破的。 Uri类的目的是提供一个URI的紧凑和标准重新presentation。 Uri类封装了所有返回的URI的规范形式和所需的逻辑,以提供对IPv4和IPv6符号支持,以及IRI的支持。

I wouldn't say the Uri class is fundamentally broken at all. The purpose of the Uri class is to provide a compact and standard representation of a URI. The Uri class encapsulates all of the logic needed to return the URI in a canonical form and to provide support for IPV4 and IPV6 notations, and IRI support.

Uri类没有被设计为允许改变乌里一旦被创建;如果你想变性的这个水平,你应该使用一个UriBuilder代替。

The Uri class is not designed to allow changing the Uri once it has been created; if you want that level of mutability you should use a UriBuilder instead.

的好处在于使用URI(或UriBuilder)以上的字符串是,你得到了很多的验证建成,以确保给定的地址是良好的,功能,使从绝对的,等等。从本质上讲,你可以相对URI认为一个开放的,作为一个实际的数据类型,所以使用一个提供了强大的打字水平。

The benefit to using Uri (or UriBuilder) over strings is that you get a lot of validation built in to ensure that the given address is well-formed, capabilities to make relative URIs from absolute ones, etc. Essentially, you can think of a Uri as an actual data type, so using one provides a level of strong typing.

这篇关于是否有任何理由使用的System.Uri?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆