Class PhysicalValue
- Namespace
- VirtualLabAPI.Core.Numerics
- Assembly
- VirtualLabAPI.dll
Class for a double value with a physical unit.
[Serializable]
public class PhysicalValue : PhysicalValueBase, IEquatable<IObjectBase>, ISerializable, IDeserializationCallback, ICloneable, IFormattable, IComparable<PhysicalValue>
- Inheritance
-
ObjectBaseSerializableObjectBaseManualSerializationPhysicalValue
- Implements
-
IEquatable<IObjectBase>
- Inherited Members
Constructors
PhysicalValue(double, MeasuredQuantity)
Default constructor.
public PhysicalValue(double value, MeasuredQuantity measuredQuantity)
Parameters
valuedoubleThe value of the PhysicalValue.
measuredQuantityMeasuredQuantityThe measured quantity of the physical value (e.g. length).
PhysicalValue(double, MeasuredQuantity, string)
Constructor with a comment string.
public PhysicalValue(double value, MeasuredQuantity measuredQuantity, string comment)
Parameters
valuedoubleThe value of the PhysicalValue.
measuredQuantityMeasuredQuantityThe measured quantity of the physical value (e.g. length).
commentstringA comment specifying what the PhysicalValue actually is.
PhysicalValue(PhysicalValue)
Copy constructor.
public PhysicalValue(PhysicalValue physicalValue)
Parameters
physicalValuePhysicalValuePhysicalValue to copy.
Properties
Value
The value of the PhysicalValue.
public virtual double Value { get; set; }
Property Value
Methods
Clone()
Overridden Clone function
public override object Clone()
Returns
- object
The cloned object.
CompareTo(PhysicalValue)
Compares the current physical value with another physical value by comparing first the physical property, then the comment and then the actual value.
public int CompareTo(PhysicalValue other)
Parameters
otherPhysicalValueA physical value to compare with this physical value.
Returns
- int
A value that indicates the relative order of the objects being compared. The return value has the following meanings: Value less than zero: This object is less than the
otherparameter. Zero: This object is equal toother. Greater than zero: This object is greater thanother.
Equals(object, EqualityIntent)
Overridden Equals functionality.
public override bool Equals(object obj, EqualityIntent equalityIntent)
Parameters
objobjectThe object to compare for equality.
equalityIntentEqualityIntentDefines what kind of equality you want to check when comparing two objects, for example all values or physical equality.
Returns
GetHashCode()
Gets a hash code.
public override int GetHashCode()
Returns
- int
The sum of the hash codes of the three properties Value, PhysicalProperty and Comment.
ToString()
Overridden ToString function. The PhysicalValue is formatted like "1 nm".
public override string ToString()
Returns
- string
The formatted value.
ToString(int)
Overridden ToString function. The PhysicalValue is formatted like "1 nm".
public override string ToString(int significantDigits)
Parameters
significantDigitsintThe number of significant digits.
Returns
- string
The formatted value.
ToString(string, IFormatProvider)
Overridden ToString function provided by the IFormattable interface. Returns a string that represents this instance.
public override string ToString(string format, IFormatProvider formatProvider = null)
Parameters
formatstringThe format. "U" or an empty string means that the string is formatted with units (e.g. "1 nm"). "G" means that the string is formatted without units (e.g. "1e-9"). "F" means that the string is formatted as "{Comment} of {Value with units}" (e.g. "wavelength of 300 nm").
In all cases you can add a number to specify the number of digits that shall be used. E.g. "U3" results in "1.23 nm", while "U4" results in "1.234 nm". You can add further formatting commands after a comma, but these are ignored. This behavior ensures that the same formatting strings can be used for both PhysicalValue and PhysicalValueComplex.
For any other string the ToString(format, formatProvider) of the Value is used.formatProviderIFormatProviderOptional culture specific format provider used for formatting the value (if format is not "U" or "F").
Returns
Operators
operator ==(PhysicalValue, PhysicalValue)
Compares two PhysicalValue for equality. The comparison will be done by comparing the values, units, and comments, respectively.
public static bool operator ==(PhysicalValue value1, PhysicalValue value2)
Parameters
value1PhysicalValueFirst PhysicalValue object to compare.
value2PhysicalValueSecond PhysicalValue object to compare.
Returns
- bool
Returns true if the two objects are equal.
operator !=(PhysicalValue, PhysicalValue)
Compares two PhysicalValue for inequality. The comparison will be done by comparing the values, units, and comments, respectively.
public static bool operator !=(PhysicalValue value1, PhysicalValue value2)
Parameters
value1PhysicalValueFirst PhysicalValue object to compare.
value2PhysicalValueSecond PhysicalValue object to compare.
Returns
- bool
Returns true if the two objects are unequal.