本文整理匯總了C#中System.Number.GetType方法的典型用法代碼示例。如果您正苦於以下問題:C# Number.GetType方法的具體用法?C# Number.GetType怎麽用?C# Number.GetType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Number
的用法示例。
在下文中一共展示了Number.GetType方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Mul
public override Number Mul(Number rhs)
{
// java NullPointerException
if(rhs == null) throw new NullReferenceException("rhs is null");
// java getClass()
if(this.GetType() != rhs.GetType())
{
// java ClassCastException
throw new InvalidCastException("rhs has illegal type");
}
Number2 cast = (Number2) rhs;
return new Number2(BigInteger.Multiply(val, cast.val));
}
示例2: Calculate
public static Number Calculate(IBinaryOperandCalculator cal, Number n1, Number n2)
{
if (n1 == null || n2 == null)
{
return 0;
}
switch (n1.TypeCode)
{
case NumberTypeCode.Int32:
return cal.Calculate((int)n1, (int)n2);
case NumberTypeCode.Int64:
return cal.Calculate((long)n1, (long)n2);
case NumberTypeCode.BigInteger:
return cal.Calculate((BigInteger)n1, (BigInteger)n2);
case NumberTypeCode.Double:
case NumberTypeCode.Decimal:
case NumberTypeCode.BigDecimal:
return cal.Calculate((BigDecimal)n1, (BigDecimal)n2);
}
throw new ArgumentException("unsupported add calculate: " + n1.GetType());
}
示例3: CompareTo
public override int CompareTo(Number rhs)
{
// java NullPointerException
if(rhs == null) throw new NullReferenceException("rhs is null");
// java getClass()
if(this.GetType() != rhs.GetType())
{
// java ClassCastException
throw new InvalidCastException("rhs has illegal type");
}
Number2 cast = (Number2) rhs;
return val.CompareTo(cast.val);
}