要获取值类型为Decimal的TypeCode,代码如下-
using System; public class Demo { public static void Main(){ Decimal val = Decimal.MaxValue; Console.WriteLine("Decimal Value = {0}", val); Console.WriteLine("HashCode = {0}", (val.GetHashCode()) ); TypeCode type = val.GetTypeCode(); Console.WriteLine("TypeCode = "+type); } }
输出结果
这将产生以下输出-
Decimal Value = 79228162514264337593543950335 HashCode = 1173356544 TypeCode = Decimal
现在让我们来看另一个示例-
using System; public class Demo { public static void Main(){ Decimal val = 3972.491M; Console.WriteLine("Decimal Value = {0}", val); Console.WriteLine("HashCode = {0}", (val.GetHashCode()) ); TypeCode type = val.GetTypeCode(); Console.WriteLine("TypeCode = "+type); } }
输出结果
这将产生以下输出-
Decimal Value = 3972.491 HashCode = 620041307 TypeCode = Decimal