Struct Number<T>
Represents any primitive numeric type.
Namespace: DotNext
Assembly: DotNext.Reflection.dll
Syntax
public struct Number<T> : IEquatable<T>, IEquatable<Number<T>>, IComparable<T> where T : struct, IConvertible, IComparable<T>, IEquatable<T>, IFormattable
Type Parameters
Name | Description |
---|---|
T | Primitive numeric type. |
Remarks
This type demonstrates how to build concept type using method from type Type<T>
Constructors
| Improve this Doc View SourceNumber(T)
Initializes a new generic numeric value.
Declaration
public Number(T value)
Parameters
Type | Name | Description |
---|---|---|
T | value | Underlying numeric value. |
Methods
| Improve this Doc View SourceEquals(T)
Determines whether this number is equal to another.
Declaration
public bool Equals(T other)
Parameters
Type | Name | Description |
---|---|---|
T | other | Other number to be compared. |
Returns
Type | Description |
---|---|
Boolean | true if this number is equal to the given number; otherwise, false. |
Equals(Object)
Determines whether this number is equal to the specified number.
Declaration
public override bool Equals(object other)
Parameters
Type | Name | Description |
---|---|---|
Object | other | The number to compare. |
Returns
Type | Description |
---|---|
Boolean | true, if two numbers are equal; otherwise, false. |
GetHashCode()
Computes hash code of the number.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
Int32 | Number hash code. |
Parse(String)
Converts the string representation of a number to its typed equivalent.
Declaration
public static Number<T> Parse(string text)
Parameters
Type | Name | Description |
---|---|---|
String | text | A string containing a number to convert. |
Returns
Type | Description |
---|---|
Number<T> | Parsed number. |
ToString()
Converts the number into string.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
String | The textual representation of the number. |
TryParse(String, out Number<T>)
Converts the string representation of a number to its typed equivalent.
Declaration
public static bool TryParse(string text, out Number<T> value)
Parameters
Type | Name | Description |
---|---|---|
String | text | A string containing a number to convert |
Number<T> | value | Converted number value. |
Returns
Type | Description |
---|---|
Boolean | Parsed number. |
TryParse(String, NumberStyles, IFormatProvider, out Number<T>)
Converts the string representation of a number to its typed equivalent.
Declaration
public static bool TryParse(string text, NumberStyles styles, IFormatProvider provider, out Number<T> value)
Parameters
Type | Name | Description |
---|---|---|
String | text | A string containing a number to convert. |
NumberStyles | styles | Style of the number supplied as a string. |
IFormatProvider | provider | An object that supplies culture-specific formatting information. |
Number<T> | value | Converted number value. |
Returns
Type | Description |
---|---|
Boolean | Parsed number. |
Operators
| Improve this Doc View SourceAddition(Number<T>, T)
Arithmetic addition operation.
Declaration
public static Number<T> operator +(Number<T> left, T right)
Parameters
Type | Name | Description |
---|---|---|
Number<T> | left | The left operand. |
T | right | The right operand. |
Returns
Type | Description |
---|---|
Number<T> | The result of addition. |
Division(Number<T>, T)
Arithmetic division operation.
Declaration
public static Number<T> operator /(Number<T> left, T right)
Parameters
Type | Name | Description |
---|---|---|
Number<T> | left | The left operand. |
T | right | The right operand. |
Returns
Type | Description |
---|---|
Number<T> | The result of division operation. |
Equality(Number<T>, T)
Performs equality check.
Declaration
public static bool operator ==(Number<T> left, T right)
Parameters
Type | Name | Description |
---|---|---|
Number<T> | left | The left operand. |
T | right | The right operand. |
Returns
Type | Description |
---|---|
Boolean | true, if two numbers are equal; otherwise, false. |
GreaterThan(Number<T>, T)
Determines whether the first number is greater than the second number.
Declaration
public static bool operator>(Number<T> left, T right)
Parameters
Type | Name | Description |
---|---|---|
Number<T> | left | The left operand. |
T | right | The right operand. |
Returns
Type | Description |
---|---|
Boolean | true if the first number is greater than the second number; otherwise, false. |
GreaterThanOrEqual(Number<T>, T)
Determines whether the first number is greater than or equal to the second number.
Declaration
public static bool operator >=(Number<T> left, T right)
Parameters
Type | Name | Description |
---|---|---|
Number<T> | left | The left operand. |
T | right | The right operand. |
Returns
Type | Description |
---|---|
Boolean | true if the first number is greater than or equal to the second number; otherwise, false. |
Implicit(Number<T> to T)
Converts container instance into the underlying numeric type.
Declaration
public static implicit operator T(Number<T> value)
Parameters
Type | Name | Description |
---|---|---|
Number<T> | value | The container instance to be converted. |
Returns
Type | Description |
---|---|
T |
Inequality(Number<T>, T)
Performs inequality check.
Declaration
public static bool operator !=(Number<T> left, T right)
Parameters
Type | Name | Description |
---|---|---|
Number<T> | left | The left operand. |
T | right | The right operand. |
Returns
Type | Description |
---|---|
Boolean | true, if two numbers are not equal; otherwise, false. |
LessThan(Number<T>, T)
Determines whether the first number is less than the second number.
Declaration
public static bool operator <(Number<T> left, T right)
Parameters
Type | Name | Description |
---|---|---|
Number<T> | left | The left operand. |
T | right | The right operand. |
Returns
Type | Description |
---|---|
Boolean | true if the first number is less than the second number; otherwise, false. |
LessThanOrEqual(Number<T>, T)
Determines whether the first number is less than or equal to the second number.
Declaration
public static bool operator <=(Number<T> left, T right)
Parameters
Type | Name | Description |
---|---|---|
Number<T> | left | The left operand. |
T | right | The right operand. |
Returns
Type | Description |
---|---|
Boolean | true if the first number is less than or equal to the second number; otherwise, false. |
Multiply(Number<T>, T)
Arithmetic multiplication operation.
Declaration
public static Number<T> operator *(Number<T> left, T right)
Parameters
Type | Name | Description |
---|---|---|
Number<T> | left | The left operand. |
T | right | The right operand. |
Returns
Type | Description |
---|---|
Number<T> | The result of multiplication operation. |
Subtraction(Number<T>, T)
Arithmetic subtraction operation.
Declaration
public static Number<T> operator -(Number<T> left, T right)
Parameters
Type | Name | Description |
---|---|---|
Number<T> | left | The left operand. |
T | right | The right operand. |
Returns
Type | Description |
---|---|
Number<T> | The result of subtraction. |
UnaryNegation(Number<T>)
Arithmetic unary minus operation.
Declaration
public static Number<T> operator -(Number<T> operand)
Parameters
Type | Name | Description |
---|---|---|
Number<T> | operand | Unary minus operand. |
Returns
Type | Description |
---|---|
Number<T> | The result of unary minus operation. |
UnaryPlus(Number<T>)
Arithmetic unary plus operation.
Declaration
public static Number<T> operator +(Number<T> operand)
Parameters
Type | Name | Description |
---|---|---|
Number<T> | operand | Unary plus operand. |
Returns
Type | Description |
---|---|
Number<T> | The result of unary plus operation. |