Unit Struct
Represents a length measurement.
[TypeConverter(typeof(UnitConverter))]
public readonly struct Unit : IEquatable<Unit>
- Implements:
- IEquatable<Unit>
Constructors
Unit(double)
Initializes an instance of the structure.
public Unit(double value)
| Parameter | Type | Description |
|---|---|---|
| value | double | The value. |
Unit(double, UnitType)
Initializes an instance of the structure.
public Unit(double value, UnitType type)
| Parameter | Type | Description |
|---|---|---|
| value | double | The value. |
| type | UnitType | The type. |
Unit(string)
Initializes an instance of the structure.
public Unit(string value)
| Parameter | Type | Description |
|---|---|---|
| value | string | The value. |
Unit(string, CultureInfo)
Initializes an instance of the structure.
public Unit(string value, CultureInfo culture)
| Parameter | Type | Description |
|---|---|---|
| value | string | The value. |
| culture | CultureInfo | The culture. |
Properties
IsEmpty
Indicates indicating whether this instance is empty.
Type
The type of units used by Value.
Value
The value.
Methods
Centimeter(double)
Creates a new Unit instance with the specified centimeters.
public static Unit Centimeter(double value)
| Parameter | Type | Description |
|---|---|---|
| value | double | The centimeter value. |
Returns
Equals(Unit)
Indicates whether the current object is equal to another object of the same type.
public bool Equals(Unit other)
| Parameter | Type | Description |
|---|---|---|
| other | Unit | An object to compare with this object. |
Returns
- bool:
trueif the current object is equal to theotherparameter; otherwise,false.
Equals(object?)
Indicates whether this instance and a specified object are equal.
public override bool Equals(object? obj)
| Parameter | Type | Description |
|---|---|---|
| obj | object | The object to compare with the current instance. |
Returns
- bool:
trueifobjand this instance are the same type and represent the same value; otherwise,false.
GetHashCode()
Returns the hash code for this instance.
public override int GetHashCode()
Returns
- int:
A 32-bit signed integer that is the hash code for this instance.
GetPixels(double)
Gets the number of pixels represented by this Unit using the specified width when the Type is set to Percentage.
Inch(double)
Creates a new Unit instance with the specified inches.
public static Unit Inch(double value)
| Parameter | Type | Description |
|---|---|---|
| value | double | The inch value. |
Returns
Parse(string)
Parses the specified string.
public static Unit Parse(string value)
| Parameter | Type | Description |
|---|---|---|
| value | string | The string to parse. |
Returns
Parse(string, CultureInfo)
Parses the specified string using the specified CultureInfo.
public static Unit Parse(string value, CultureInfo culture)
| Parameter | Type | Description |
|---|---|---|
| value | string | The string to parse. |
| culture | CultureInfo | The culture. |
Returns
Percentage(double)
Creates a new Unit instance with the specified percentage.
public static Unit Percentage(double value)
| Parameter | Type | Description |
|---|---|---|
| value | double | The percentage value. |
Returns
Pixel(double)
Creates a new Unit instance with the specified pixels.
public static Unit Pixel(double value)
| Parameter | Type | Description |
|---|---|---|
| value | double | The pixel value. |
Returns
Point(double)
Creates a new Unit instance with the specified points.
public static Unit Point(double value)
| Parameter | Type | Description |
|---|---|---|
| value | double | The point value. |
Returns
ToString()
Returns the string representation of this object.
ToString(IFormatProvider)
Returns a string representation of this instance using the specified IFormatProvider to convert the Value.
public string ToString(IFormatProvider formatProvider)
| Parameter | Type | Description |
|---|---|---|
| formatProvider | IFormatProvider | The format provider. |
Returns
ValidateIsGreaterThan(object, double)
Validates that the object is a Unit greater than the specified number.
public static bool ValidateIsGreaterThan(object value, double min)
| Parameter | Type | Description |
|---|---|---|
| value | object | The object to validate. |
| min | double | The number that the value must be greater than. |
Returns
- bool:
trueif the validation is successful; otherwise,false.
ValidateIsGreaterThanOrEqual(object, double)
Validates that the object is a Unit greater than or equal to the specified number.
public static bool ValidateIsGreaterThanOrEqual(object value, double min)
| Parameter | Type | Description |
|---|---|---|
| value | object | The object to validate. |
| min | double | The number that the value must be greater than or equal to. |
Returns
- bool:
trueif the validation is successful; otherwise,false.
ValidateIsPositive(object)
Validates that the object is a Unit greater than or equal to 0.
public static bool ValidateIsPositive(object value)
| Parameter | Type | Description |
|---|---|---|
| value | object | The object to validate. |
Returns
- bool:
trueif the validation is successful; otherwise,false.
Operators
operator ==(Unit, Unit)
Compares two Unit objects to determine whether they are equal.
public static bool operator ==(Unit left, Unit right)
| Parameter | Type | Description |
|---|---|---|
| left | Unit | The left. |
| right | Unit | The right. |
Returns
implicit operator Unit(double)
public static implicit operator Unit(double value)
| Parameter | Type | Description |
|---|---|---|
| value | double | The value. |
Returns
operator !=(Unit, Unit)
Compares two Unit objects to determine whether they are not equal.
public static bool operator !=(Unit left, Unit right)
| Parameter | Type | Description |
|---|---|---|
| left | Unit | The left. |
| right | Unit | The right. |
Returns
Fields
Empty
Represents an empty Unit.
public static readonly Unit Empty