?? portrange.cs
字號:
using System;
using System.Collections.Generic;
using System.Text;
namespace SDP
{
/// <summary>
/// This class describes a range of ports.
/// </summary>
public class PortRange
{
private ushort port;
/// <summary>
/// Gets or sets the value of the starting port.
/// </summary>
public ushort Port
{
get { return this.port; }
set { this.port = value; }
}
private ushort numberOfPorts;
/// <summary>
/// Gets or sets the number of ports in the range.
/// </summary>
public ushort NumberOfPorts
{
get { return this.numberOfPorts; }
set
{
if (value <= 0) throw new ArgumentException("The number of ports must be greater than or equal to one.");
if (this.port + value - 1 > 65535) throw new OverflowException("This number of ports causes the end of the port range to be invalid.");
this.numberOfPorts = value;
}
}
/// <summary>
/// Instantiates a new PortRange.
/// </summary>
/// <param name="port">The starting port. The default number of ports is one, so this
/// range is effectively one port.</param>
public PortRange(ushort port) : this(port, 1) { }
/// <summary>
/// Instantiates a new PortRange.
/// </summary>
/// <param name="port">The starting port.</param>
/// <param name="numberOfPorts">The number of ports in the range. This value must
/// be greater than or equal to one.</param>
public PortRange(ushort port, ushort numberOfPorts)
{
this.Port = port;
this.NumberOfPorts = numberOfPorts;
}
/// <summary>
/// Converts this PortRange to its string representation.
/// </summary>
/// <returns>A string.</returns>
public override string ToString()
{
string s = this.port.ToString();
if (this.numberOfPorts == 1) return s;
return s + "/" + this.numberOfPorts.ToString();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -