简体   繁体   English

是否可以创建不是绝对的Uri?

[英]Is it possible to create a Uri that is not absolute?

I am curious about the Uri property: 我对Uri物业感到好奇:

public bool IsAbsoluteUri { get; }

Is it ever possible for it to be false? 是否有可能是假的? It doesn't seem that I can create a Uri that is not absolute. 似乎我不能创建不是绝对的Uri。 The latter (uriTwo) throws: 后者(uriTwo)抛出:

var uriOne = new Uri( "http://stackoverflow.com/about" );
var uriTwo = new Uri( "/about" );

Same seems to be true with the builder. 对于构建器来说似乎也是如此。 What am I missing? 我想念什么?

Yes. 是。 Try the following 尝试以下

var uri = new Uri("foo.jpg", UriKind.Relative);
Console.WriteLine(uri.IsAbsoluteUri); // prints false

You need to use another constructor that takes a UriKind , for instance . 您需要使用另一个构造函数,一个UriKind例如 The constructor that takes just a path assumes absolute kind. 仅采用路径的构造函数假定绝对类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM