語言

PingOptions 建構函式

定義

初始化 PingOptions 類別的新執行個體。

多載

名稱 Description
PingOptions()

初始化 PingOptions 類別的新執行個體。

PingOptions(Int32, Boolean)

初始化該類別的新實例 PingOptions ,並設定存活時間與碎片值。

PingOptions()

來源:
PingOptions.cs
來源:
PingOptions.cs
來源:
PingOptions.cs
來源:
PingOptions.cs
來源:
PingOptions.cs

初始化 PingOptions 類別的新執行個體。

public:
 PingOptions();
public PingOptions();
Public Sub New ()

範例

以下程式碼範例示範呼叫此建構子。

Ping pingSender = new Ping ();
PingOptions options = new PingOptions ();

// Use the default Ttl value which is 128,
// but change the fragmentation behavior.
options.DontFragment = true;

備註

下表顯示 PingOptions實例的初始屬性值。

房產 初始值
Ttl 128
DontFragment false

你可以在呼叫 Send 或 SendAsync之前將屬性設定為新的值。

適用於

PingOptions(Int32, Boolean)

來源:
PingOptions.cs
來源:
PingOptions.cs
來源:
PingOptions.cs
來源:
PingOptions.cs
來源:
PingOptions.cs

初始化該類別的新實例 PingOptions ,並設定存活時間與碎片值。

public:
 PingOptions(int ttl, bool dontFragment);
public PingOptions(int ttl, bool dontFragment);
new System.Net.NetworkInformation.PingOptions : int * bool -> System.Net.NetworkInformation.PingOptions
Public Sub New (ttl As Integer, dontFragment As Boolean)

參數

ttl
Int32

一個 Int32 大於零的值,表示資料封包可轉發的次數 Ping 。

dontFragment
Boolean

true以防止傳送至遠端主機的資料被分割;否則,。 false

例外狀況

ttl 小於或等於零。

範例

以下程式碼範例示範呼叫此建構子並顯示新實例的屬性值。

// Set options for transmission:
// The data can go through 64 gateways or routers
// before it is destroyed, and the data packet
// cannot be fragmented.
PingOptions options = new PingOptions (64, true);

Console.WriteLine ("Time to live: {0}", options.Ttl);
Console.WriteLine ("Don't fragment: {0}", options.DontFragment);

備註

該 ttl 參數限制可轉發資料的路由器與閘道器數量。 這對於測試本地與遠端電腦之間路由長度非常有用。 這個 dontFragment 參數讓你能測試用於傳送封包的路由器和閘道器的最大傳輸單元(MTU)。

適用於