locked
VB.Net - Specifications says String is a Primitive RRS feed

  • Question

  • User37182867 posted

    According to https://msdn.microsoft.com/en-us/library/aa711900(v=vs.71).aspx

    A string is a primitive how ever

    GetType(System.String).IsPrimitive

    returns false.

    Can anyone explain this. I know C# does not technically have primitives however, according to documentation primitives are listed as any types defined directly under System which includes String. 

    Is this a documentation error or an error with the IsPrimitive method?

    Friday, June 26, 2015 11:52 AM

Answers

  • User753101303 posted

    Hi,

    IMO this is just because this is not the exact same definition. This link defines a primitive type from a language perspective. IsPrimitive defines rather a primitive type from a .NET runtime perspective:


    - defined as a type that doesn't depend on other types (likely coming itself from the underlying CPU architecture), String is basically an array of chars and is not a CLR primitive type
    - defined as a type having its own keyword in VB (or C#), it is a language primitive type

    So in short we don't have a single "primitive type" definition but rather a "CLR primitive type" definiition and a "VB primitive type" definition.

    Edit: BTW should be the same for dates. It has a language keyword in VB, but from an architecture perspective it is a 64 bit value so µI would say :
    - System.DateTime is not a CLR primitive type
    - it is not a C# primitive type
    - it is a VB primitive type

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 26, 2015 12:36 PM

All replies

  • User753101303 posted

    Hi,

    IMO this is just because this is not the exact same definition. This link defines a primitive type from a language perspective. IsPrimitive defines rather a primitive type from a .NET runtime perspective:


    - defined as a type that doesn't depend on other types (likely coming itself from the underlying CPU architecture), String is basically an array of chars and is not a CLR primitive type
    - defined as a type having its own keyword in VB (or C#), it is a language primitive type

    So in short we don't have a single "primitive type" definition but rather a "CLR primitive type" definiition and a "VB primitive type" definition.

    Edit: BTW should be the same for dates. It has a language keyword in VB, but from an architecture perspective it is a 64 bit value so µI would say :
    - System.DateTime is not a CLR primitive type
    - it is not a C# primitive type
    - it is a VB primitive type

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 26, 2015 12:36 PM
  • User37182867 posted

    Good perspective Patrice, thanks. 

    Been writing to much reflection code lately and keep running across this. I think I finally just started checking IsPrimitive, ValueType and Type=String which seemed to clear up issues I was having.

    Friday, June 26, 2015 1:03 PM