PingOptions Constructors
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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.
public:
PingOptions();
public PingOptions ();
Public Sub New ()
Examples
The following code example demonstrates calling this constructor.
Ping ^ pingSender = gcnew Ping;
PingOptions ^ options = gcnew PingOptions;
// Use the default Ttl value which is 128,
// but change the fragmentation behavior.
options->DontFragment = true;
Ping pingSender = new Ping ();
PingOptions options = new PingOptions ();
// Use the default Ttl value which is 128,
// but change the fragmentation behavior.
options.DontFragment = true;
let pingSender = new Ping()
// Use the default Ttl value which is 128,
// but change the fragmentation behavior.
let options = PingOptions()
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
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.
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)
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.
// 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 = gcnew PingOptions( 64,true );
Console::WriteLine( "Time to live: {0}", options->Ttl );
Console::WriteLine( "Don't fragment: {0}", options->DontFragment );
// 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.