PingOptions Constructors

Definition

Initializes a new instance of the PingOptions class.

Overloads

PingOptions()

Initializes a new instance of the PingOptions class.

PingOptions(Int32, Boolean)

Initializes a new instance of the PingOptions class and sets the Time to Live and fragmentation values.

PingOptions()

Source:
PingOptions.cs
Source:
PingOptions.cs
Source:
PingOptions.cs

Initializes a new instance of the PingOptions class.

C#
public PingOptions();

Examples

The following code example demonstrates calling this constructor.

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;

Remarks

The following table shows initial property values for an instance of PingOptions.

Property Initial Value
Ttl 128
DontFragment false

You can set the properties to new values before calling Send or SendAsync.

Applies to

.NET 10 and other versions
Product Versions
.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)

Source:
PingOptions.cs
Source:
PingOptions.cs
Source:
PingOptions.cs

Initializes a new instance of the PingOptions class and sets the Time to Live and fragmentation values.

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

Parameters

ttl
Int32

An Int32 value greater than zero that specifies the number of times that the Ping data packets can be forwarded.

dontFragment
Boolean

true to prevent data sent to the remote host from being fragmented; otherwise, false.

Exceptions

ttl is less than or equal to zero.

Examples

The following code example demonstrates calling this constructor and displaying the new instance's property values.

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);

Remarks

The ttl parameter limits the number of routers and gateways that can forward the data. This is useful for testing the length of the route between the local and remote computers. The dontFragment parameter allows you to test the maximum transmission unit (MTU) of the routers and gateways used to transmit the packet.

Applies to

.NET 10 and other versions
Product Versions
.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