DistanceTryParse Method (String, IFormatProvider, DistanceUnitType, Distance)

Attempts to parse a distance from a string representation using the current units.

Namespace:  Tekla.Structures.Datatype
Assembly:  Tekla.Structures.Datatype (in Tekla.Structures.Datatype.dll) Version: 2024.0.0+a110b435391768740483e3032720a566518c9a63
public static bool TryParse(
	string text,
	IFormatProvider formatProvider,
	DistanceUnitType defaultUnitType,
	out Distance result


Type: SystemString
The text to parse.
Type: SystemIFormatProvider
The number format provider.
Type: Tekla.Structures.DatatypeDistanceUnitType
The default unit type if the unit cannot be determined.
Type: Tekla.Structures.DatatypeDistance
The output variable for the result.

Return Value

Type: Boolean
A boolean value indicating whether the operation succeeded.
ArgumentExceptionThrown if an invalid unit type is specified.
This example shows how to specify a format provider and a unit type when attempting to parse a Distance instance from a string.
using Tekla.Structures.Datatype;
using System.Globalization;

public class Example
       public void Example1()
           Distance.CurrentUnitType = Distance.UnitType.Millimeter;

           // If the string can not be parsed, an exception is thrown. To prevent the
           // exception we can use the Distance.TryParse instead. We'll use this variable
           // to hold the parsed value.
           Distance distance;

           // Distance.TryParse works just like the Distance.Parse method, except the method
           // returns a boolean value indicating whether the string was parsed and takes an
           // output variable for holding the result.
           bool parsed = Distance.TryParse("30.2", CultureInfo.InvariantCulture, Distance.UnitType.Inch, out distance);
See Also
Was this helpful?
The feedback you give here is not visible to other users. We use your comments to improve the content.