Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Uri.Port Property

Gets the port number of the specified URI.

[Visual Basic]
Public ReadOnly Property Port As Integer
[C#]
public int Port {get;}
[C++]
public: __property int get_Port();
[JScript]
public function get Port() : int;

Property Value

The integer port number of the specified URI.

Remarks

The port number defines the protocol port used for contacting the server referenced in the URI. If a port is not is not specified as part of the URI, the Port property returns the default value for the protocol.

Example

The following example writes the URI's port number to the console. In this case, the value is the default port number for HTTP, port 80.

[Visual Basic] 
Dim baseUri As New Uri("http://www.contoso.com/")
Dim myUri As New Uri(baseUri, "catalog/shownew.htm?date=today")
       
Console.WriteLine(myUri.Port)


[C#] 
Uri baseUri = new Uri("http://www.contoso.com/");
 Uri myUri = new Uri(baseUri,"catalog/shownew.htm?date=today");
 
 Console.WriteLine(myUri.Port);
   

[C++] 
Uri* baseUri = new Uri(S"http://www.contoso.com/");
Uri* myUri = new Uri(baseUri,S"catalog/shownew.htm?date=today");
 
Console::WriteLine(myUri->Port);


[JScript] 
var baseUri : Uri = new Uri("http://www.contoso.com/");
var myUri : Uri = new Uri(baseUri,"catalog/shownew.htm?date=today");
Console.WriteLine(myUri.Port);

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

Uri Class | Uri Members | System Namespace

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2015 Microsoft