PingOptions 建構函式

定義

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

多載

PingOptions()

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

PingOptions(Int32, Boolean)

初始化 PingOptions 類別的新執行個體,並設定「存留時間」和分割值。

PingOptions()

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

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

C#
public PingOptions();

範例

下列程式代碼範例示範如何呼叫這個建構函式。

C#
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

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

適用於

.NET 10 及其他版本
產品 版本
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

PingOptions(Int32, Boolean)

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

初始化 PingOptions 類別的新執行個體,並設定「存留時間」和分割值。

C#
public PingOptions(int ttl, bool dontFragment);

參數

ttl
Int32

大於零的 Int32 值,指定可以轉送 Ping 資料封包的次數。

dontFragment
Boolean

true 表示不要分割傳送到遠端主機的資料,否則為 false

例外狀況

ttl 小於或等於零。

範例

下列程式代碼範例示範呼叫這個建構函式,並顯示新實例的屬性值。

C#
// 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) 。

適用於

.NET 10 及其他版本
產品 版本
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1