Why is decimal not a primitive type?

前端 未结 3 410
自闭症患者
自闭症患者 2020-12-11 00:34

Why is decimal not a primitive type?

Console.WriteLine(typeof(decimal).IsPrimitive);

outputs false.

It is

3条回答
  •  时光取名叫无心
    2020-12-11 01:12

    Consider the below example ,

         int i = 5;
        float f = 1.3f;
        decimal d = 10;
    

    If you put a debugger and verify the native instruction set,it would be

    As you can see int,float all being a primitive type takes single instruction to perform the assignemnt operation whereas decimal,string being non primitive types takes more than one native instruction to perform this operation.

提交回复
热议问题