Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#为System.Uri属性指定默认值_C#_Properties - Fatal编程技术网

C#为System.Uri属性指定默认值

C#为System.Uri属性指定默认值,c#,properties,C#,Properties,我有一个关于RESTfulAPI的项目,我有一个基本URL作为属性,每次我都需要在上面添加部分(这在我的方法中)。我需要(a)声明默认(未更改)路径,然后(b)关于如何添加到URL的帮助。例如: public partial class APIParamaters { public System.Uri URL { get; set; } = (System.Uri) "http://192.100.106.657:8811/some/part/here/version1/api

我有一个关于RESTfulAPI的项目,我有一个基本URL作为属性,每次我都需要在上面添加部分(这在我的方法中)。我需要(a)声明默认(未更改)路径,然后(b)关于如何添加到URL的帮助。例如:

    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 !!!
}
这是一个错误,我不知道如何纠正。 另外,我以后如何添加到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..
    };
}
以下代码表示(将此
字符串转换为
System.Uri
),但不能将字符串转换为
System.Uri

(System.Uri) "http://192.100.106.657:8811/some/part/here/version1/api";
public System.Uri URL { get; set; } = new System.Uri("http://192.100.106.657:8811/some/part/here/version1/api");
您应该实例化
System.Uri

(System.Uri) "http://192.100.106.657:8811/some/part/here/version1/api";
public System.Uri URL { get; set; } = new System.Uri("http://192.100.106.657:8811/some/part/here/version1/api");

这回答了你的问题吗?对于您得到的错误是重复的。这是否回答了您的问题?非常感谢,工作做得很好。关于如何在末尾添加部分的任何想法(参考问题的“public APIParamaters myParams=new apiparamates”部分)。非常感谢你!