In This Article

Unit Struct

Represents a length measurement.

[TypeConverter(typeof(UnitConverter))]
public struct Unit

Constructors

Unit(double)

Initializes a new instance of the Unit struct.

public Unit(double value)
Parameter Type Description
value double

The value.

Unit(double, UnitType)

Initializes a new instance of the Unit struct.

public Unit(double value, UnitType type)
Parameter Type Description
value double

The value.

type UnitType

The type.

Unit(string)

Initializes a new instance of the Unit struct.

public Unit(string value)
Parameter Type Description
value string

The value.

Unit(string, CultureInfo)

Initializes a new instance of the Unit struct.

public Unit(string value, CultureInfo culture)
Parameter Type Description
value string

The value.

culture CultureInfo

The culture.

Properties

IsEmpty

Gets a value indicating whether this instance is empty.

public bool IsEmpty { get; }

Property Value

bool:

true if this instance is empty; otherwise, false.

Type

Gets the type of units used by Value.

public UnitType Type { get; }

Property Value

UnitType:

The type of units.

Value

Gets the value.

public double Value { get; }

Property Value

double:

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

Unit

Equals(object)

Indicates whether this instance and a specified object are equal.

public override bool Equals(object obj)
Parameter Type Description
obj object

Another object to compare to.

Returns

bool:

true if obj and 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.

public double GetPixels(double width)
Parameter Type Description
width double

The width.

Returns

double

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

Unit

Parse(string)

Parses the specified string.

public static Unit Parse(string value)
Parameter Type Description
value string

The string to parse.

Returns

Unit

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

Unit

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

Unit

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

Unit

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

Unit

ToString()

Returns a string representation of this instance.

public override string ToString()

Returns

string:

A string representation of this instance.

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

string

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:

true if 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:

true if 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:

true if 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

bool:

true if both Unit objects are equal; otherwise, false.

implicit operator Unit(double)

Performs an implicit conversion from double to Unit.

public static implicit operator Unit(double value)
Parameter Type Description
value double

The value.

Returns

Unit:

The result of the conversion.

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

bool:

true if both Unit objects are not equal; otherwise, false.

Fields

Empty

Represents an empty Unit. This field is read-only.

public static readonly Unit Empty

Inherited Members