How do I tell if a type is a “simple” type? i.e. holds a single value

后端 未结 7 1940
北荒
北荒 2020-12-01 02:46
typeof(string).IsPrimitive == false
typeof(int).IsPrimitive == true
typeof(MyClass).IsClass == true
typeof(string).IsClass == true
typeof(string).IsByRef == false
ty         


        
7条回答
  •  抹茶落季
    2020-12-01 03:04

    Strings aren't primitives, if I recall correctly. even though there is a keyword for it, a string is an object. Your call to IsPrimitive will accurately tell you if something is a primitive.

提交回复
热议问题