Question: I have the following code to concat some URIs:

```
public static Uri BuildUri()
{
    Uri baseUri = new Uri("http://192.168.1.60:8080");
    Uri restUri = new Uri(baseUri, "/rest/api/2");
    Uri url = new Uri(restUri, "/mypreferences?key=my.config.value");

    return url;
}

```

I expect the following address, in the result URI:

```
http://192.168.1.60:8080/rest/api/2/mypreferences?key=my.config.value

```

But I'm getting:

```
http://192.168.1.60:8080/mypreferences?key=my.config.value

```

Would someone please could explain why?

Answer: 
Try this ie, you need to change the last url. You are passing the `baseUri` however you should pass the `restUri`:

```
Uri baseUri = new Uri("http://192.168.1.60:8080");
Uri restUri = new Uri(baseUri, "/rest/api/2/");
Uri url = new Uri(restUri, "mypreferences?key=my.config.value");   
                   ^^^^^^---Here

```
You use the baseUri in both creating the restUri and url. You probably meant to do this instead:

```
public static Uri BuildUri()
{
    Uri baseUri = new Uri("http://192.168.1.60:8080");
    Uri restUri = new Uri(baseUri, "rest/api/2");
    Uri url = new Uri(restUri, "mypreferences?key=my.config.value");
    return url;
}

```

Use baseUri to create restUri and use restUri to create the final url. Also notice how i have left out the leading slashes in the sub urls. The Uri class will handle the correct concatenation for you.