If I create a Uri using the UriBuilder like this:
var rootUrl = new UriBuilder(\"http\", \"example.com\", 50000).Uri;
You can use the Uri.GetComponents method:
rootUrl.GetComponents(UriComponents.SchemeAndServer, UriFormat.UriEscaped)
Which would return a string representation of the Uri's different components, in this case, UriComponents.SchemeAndServer means the scheme, host, and port components.
You can read more about it on MSDN:
Uri.GetComponents
UriComponents
UriFormat