[英]C# Assigning default value to System.Uri property
I have a project which is about RESTful API and I have as a property the basic URL, on which I need to add parts each time (that's in my methods).我有一个关于 RESTful API 的项目,我将基本 URL 作为属性,我每次都需要在其上添加部分(在我的方法中)。 I need (a) to declare the default (unchanged) path, and then (b) some help on how do I add to the URL.
我需要 (a) 声明默认(未更改)路径,然后 (b) 关于如何添加到 URL 的一些帮助。 Example:
例子:
public partial class APIParamaters
{
public System.Uri URL { get; set; } = (System.Uri) "http://192.100.106.657:8811/some/part/here/version1/api"; //throws error !!!
}
This is throwing an error and I don't know how to correct.这是抛出错误,我不知道如何纠正。 Also, how do I later add to the URL, for example, I am trying
另外,我以后如何添加到 URL,例如,我正在尝试
class MyTest
{
public string SpecialPart = "Excellent";
public APIParamaters myParams = new APIParamaters
{
URL = URL + SpecialPart + "FirstCall", //trying to do: "http://192.100.106.657:8811/some/part/here/version1/api/Excellent/FirstCall"
SomethingElse = "Ok"
//etc..
};
}
The following code means (cast this string
as System.Uri
) but string can not be cast as System.Uri
:以下代码表示(将此
string
为System.Uri
)但字符串不能转换为System.Uri
:
(System.Uri) "http://192.100.106.657:8811/some/part/here/version1/api";
You should instantiate System.Uri
:您应该实例化
System.Uri
:
public System.Uri URL { get; set; } = new System.Uri("http://192.100.106.657:8811/some/part/here/version1/api");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.