Is int (Int32) considered an object in .NET or a primitive (not int?)?

前端 未结 6 1787
小蘑菇
小蘑菇 2020-12-31 20:19

Is int (aka Int32) an object , or a primitive in .NET (I\'m not asking regarding int?)?

I hit F12 on the saved word int and g

6条回答
  •  离开以前
    2020-12-31 20:46

    Int32 is a struct, which is like a type (compile time) and not an object (run time). So you can't say "Int32 is an object", but you could say "Int32 inherits from object".

    A struct is a ValueType and a ValueType derives from object.

    int and Int32 and synonyms where Int32 is better suited in operations where the reader cares about the length in bits (bit fiddling operations, overflow situations etc.)

提交回复
热议问题