Length Struct
Represents a length, distance or a coordinate.
public struct Length : IComparable<Length>, IEquatable<Length>, IFormattable
Public Structure Length
Implements IComparable(Of Length), IEquatable(Of Length), IFormattable
Remarks
Length internally stores its value in an System.Int64 field and internally uses EMU (English Metric Unit) as a unit of measurement.
EMU (English Metric Unit) can evenly divide in both English and Metric units and can avoid rounding errors during the calculation since it defines an integer based, high precision coordinate system (1" = 914 400 EMU, 1 cm = 360 000 EMU, 1 mm = 36 000 EMU, 1 pt = 12 700 EMU).
Properties
DefaultUnit
Gets or sets the default measurement unit that is applied globally every time Length is converted from/to a System.Double and to a System.String.
public static LengthUnit DefaultUnit { get; set; }
Public Shared Property DefaultUnit As LengthUnit
Property Value
The default measurement unit.
Remarks
Initial value is Point.
This property makes code less verbose and, thus, easier to read and maintain because instead of using From(Double, LengthUnit), To(LengthUnit) and ToString(LengthUnit) methods, one can use implicit conversions from/to a System.Double and to a System.String.
Since default measurement unit is applied globally (like any other static member), it is advisable not to set DefaultUnit property or use implicit conversions from/to a System.Double and to a System.String if GemBox.Presentation is used by various application functions that expect different default measurement unit, especially if usage is multi-threaded.
Methods
CompareTo(Length)
Compares the value of this instance to a specified Length value and returns an integer that indicates whether this instance is less than, equal to, or greater than the specified Length value.
Parameters
other
- Length
The object to compare to the current instance.
Returns
- System.Int32
A signed number indicating the relative values of this instance and the other
parameter.
If returned value is less than zero, then this instance is less than other
; else, if it is zero, then this instance is equal to other
; else (if it is greater than zero) this instance is greater than other
.
Equals(Length)
Parameters
other
- Length
The other length to compare with this length instance.
Returns
Equals(Object)
Determines whether the specified System.Object is equal to this Length instance.
public override bool Equals(object obj)
Public Overrides Function Equals(obj As Object) As Boolean
Parameters
obj
- System.Object
The System.Object to compare with this length instance.
Returns
- System.Boolean
Overrides
From(Double, LengthUnit)
Converts a length value in a specified measurement unit to a Length instance.
public static Length From(double value, LengthUnit unit)
Public Shared Function From(value As Double, unit As LengthUnit) As Length
Parameters
value
- System.Double
The length value.
unit
- LengthUnit
The measurement unit.
Returns
A Length instance that is equivalent to a specified input length in a specified measurement unit.
GetHashCode()
Returns a hash code for this Length instance.
Returns
- System.Int32
An integer value that specifies a hash value for this Length instance.
Overrides
To(LengthUnit)
Converts this Length instance to a length value in a specified measurement unit.
Parameters
unit
- LengthUnit
The measurement unit.
Returns
- System.Double
A length value that is equivalent to this Length instance in a specified measurement unit.
ToString()
Returns a System.String that represents this Length instance in a DefaultUnit.
Returns
- System.String
A System.String that represents this Length instance in a default measurement unit.
Overrides
ToString(LengthUnit)
Returns a System.String that represents this Length instance in a specified measurement unit.
public string ToString(LengthUnit unit)
Public Function ToString(unit As LengthUnit) As String
Parameters
unit
- LengthUnit
The measurement unit.
Returns
- System.String
A System.String that represents this Length instance in a specified measurement unit.
ToString(String, IFormatProvider)
Returns a System.String that represents this Length instance in a specified format and a DefaultUnit by using a specified format provider.
public string ToString(string format, IFormatProvider formatProvider)
Public Function ToString(format As String, formatProvider As IFormatProvider) As String
Parameters
format
- System.String
The format.
formatProvider
- System.IFormatProvider
The format provider.
Returns
- System.String
A System.String that represents this Length instance in a specified format and a DefaultUnit by using a specified format provider.
ToString(String, IFormatProvider, LengthUnit)
Returns a System.String that represents this Length instance in a specified format and a measurement unit by using a specified format provider.
public string ToString(string format, IFormatProvider formatProvider, LengthUnit unit)
Public Function ToString(format As String, formatProvider As IFormatProvider, unit As LengthUnit) As String
Parameters
format
- System.String
The format.
formatProvider
- System.IFormatProvider
The format provider.
unit
- LengthUnit
The measurement unit.
Returns
- System.String
A System.String that represents this Length instance in a specified format and a measurement unit by using a specified format provider.
Operators
Equality(Length, Length)
Determines whether first
and second
Lengths are equal.
public static bool operator ==(Length first, Length second)
Public Shared Operator =(first As Length, second As Length) As Boolean
Parameters
first
- Length
The first length.
second
- Length
The second length.
Returns
- System.Boolean
true if first
and second
lengths are equal; otherwise, false.
Explicit(Length to Int64)
Converts a Length instance to a length value in an EMU (English Metric Unit) measurement unit.
public static explicit operator long (Length value)
Public Shared Narrowing Operator CType(value As Length) As Long
Parameters
value
- Length
The length value.
Returns
- System.Int64
A length value that is equivalent to a specified input Length instance in an EMU (English Metric Unit) measurement unit.
Explicit(Int64 to Length)
Converts a length value in an EMU (English Metric Unit) measurement unit to a Length instance.
public static explicit operator Length(long value)
Public Shared Narrowing Operator CType(value As Long) As Length
Parameters
value
- System.Int64
The length value.
Returns
A Length instance that is equivalent to a specified input length in an EMU (English Metric Unit) measurement unit.
GreaterThan(Length, Length)
public static bool operator>(Length first, Length second)
Public Shared Operator>(first As Length, second As Length) As Boolean
Parameters
first
- Length
The first length.
second
- Length
The second length.
Returns
- System.Boolean
true if first
length is greater than second
length; otherwise, false.
GreaterThanOrEqual(Length, Length)
public static bool operator >=(Length first, Length second)
Public Shared Operator >=(first As Length, second As Length) As Boolean
Parameters
first
- Length
The first length.
second
- Length
The second length.
Returns
- System.Boolean
true if first
length is greater than or equal to second
length; otherwise, false.
Implicit(Length to Double)
Converts a Length instance to a length value in a DefaultUnit.
public static implicit operator double (Length value)
Public Shared Widening Operator CType(value As Length) As Double
Parameters
value
- Length
The length value.
Returns
- System.Double
A length value that is equivalent to a specified input Length instance in a DefaultUnit.
Implicit(Double to Length)
Converts a length value in a DefaultUnit to a Length instance.
public static implicit operator Length(double value)
Public Shared Widening Operator CType(value As Double) As Length
Parameters
value
- System.Double
The length value.
Returns
A Length instance that is equivalent to a specified input length in a DefaultUnit.
Inequality(Length, Length)
Determines whether first
and second
Lengths are not equal.
public static bool operator !=(Length first, Length second)
Public Shared Operator <>(first As Length, second As Length) As Boolean
Parameters
first
- Length
The first length.
second
- Length
The second length.
Returns
- System.Boolean
true if first
and second
lengths are not equal; otherwise, false.
LessThan(Length, Length)
public static bool operator <(Length first, Length second)
Public Shared Operator <(first As Length, second As Length) As Boolean
Parameters
first
- Length
The first length.
second
- Length
The second length.
Returns
- System.Boolean
true if first
length is less than second
length; otherwise, false.
LessThanOrEqual(Length, Length)
public static bool operator <=(Length first, Length second)
Public Shared Operator <=(first As Length, second As Length) As Boolean
Parameters
first
- Length
The first length.
second
- Length
The second length.
Returns
- System.Boolean
true if first
length is less than or equal to second
length; otherwise, false.