Expand Minimize

Type::IsPrimitiveImpl Method

When overridden in a derived class, implements the IsPrimitive property and determines whether the Type is one of the primitive types.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

protected:
virtual bool IsPrimitiveImpl() abstract

Return Value

Type: System::Boolean
true if the Type is one of the primitive types; otherwise, false.

The primitive types are Boolean, Byte, SByte, Int16, UInt16, Int32, UInt32, Int64, UInt64, Char, Double, and Single.

The following example determines whether the given type is a primitive type and displays the result.

using namespace System;
using namespace System::Reflection;

public ref class MyTypeDelegatorClass: public TypeDelegator
{
public:
   String^ myElementType;

private:
   Type^ myType;

public:
   MyTypeDelegatorClass( Type^ myType )
      : TypeDelegator( myType )
   {
      this->myType = myType;
   }

protected:

   // Override the IsPrimitiveImpl. 
   virtual bool IsPrimitiveImpl() override
   {

      // Determine whether the type is a primitive type. 
      if ( myType->IsPrimitive )
      {
         myElementType = "primitive";
         return true;
      }

      return false;
   }
};

int main()
{
   try
   {
      Console::WriteLine( "Determine whether int is a primitive type." );
      MyTypeDelegatorClass^ myType;
      myType = gcnew MyTypeDelegatorClass( int::typeid );

      // Determine whether int is a primitive type. 
      if ( myType->IsPrimitive )
      {
         Console::WriteLine( "{0} is a primitive type.", int::typeid );
      }
      else
      {
         Console::WriteLine( "{0} is not a primitive type.", int::typeid );
      }
      Console::WriteLine( "\nDetermine whether String is a primitive type." );
      myType = gcnew MyTypeDelegatorClass( String::typeid );

      // Determine if String is a primitive type. 
      if ( myType->IsPrimitive )
      {
         Console::WriteLine( "{0} is a primitive type.", String::typeid );
      }
      else
      {
         Console::WriteLine( "{0} is not a primitive type.", String::typeid );
      }
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( "Exception: {0}", e->Message );
   }
}

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone Silverlight 8.1, Windows Phone Silverlight 8

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft