Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

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
protected abstract boolean IsPrimitiveImpl ()
protected abstract function IsPrimitiveImpl () : boolean
Not applicable.

Return Value

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 );
   }
}

import System.*;
import System.Reflection.*;
public class MyTypeDelegatorClass extends TypeDelegator
{
    public String myElementType = null;
    private Type myType = null;

    public MyTypeDelegatorClass(Type myType)
    {
        super(myType);
        this.myType = myType;
    } //MyTypeDelegatorClass

    // Override the IsPrimitiveImpl.
    protected boolean IsPrimitiveImpl()
    {
        // Determine whether the type is a primitive type.
        if (myType.get_IsPrimitive()) {
            myElementType = "primitive";
            return true;
        }
        return false;
    } //IsPrimitiveImpl
} //MyTypeDelegatorClass

public class MyTypeDemoClass
{
    public static void main(String[] args)
    {
        try {
            Console.WriteLine("Determine whether int is a primitive type.");
            MyTypeDelegatorClass myType;
            myType = new MyTypeDelegatorClass(int.class.ToType());
            // Determine whether int is a primitive type.
            if (myType.get_IsPrimitive()) {
                Console.WriteLine(int.class.ToType() + " is a primitive type.");
            }
            else {
                Console.WriteLine(int.class.ToType() 
                    + " is not a primitive type.");
            }
            Console.WriteLine("\nDetermine whether string is a primitive type.");
            myType = new MyTypeDelegatorClass(String.class.ToType());
            // Determine if string is a primitive type.
            if (myType.get_IsPrimitive()) {
                Console.WriteLine(String.class.ToType() 
                    + " is a primitive type.");
            }
            else {
                Console.WriteLine(String.class.ToType() 
                    + " is not a primitive type.");
            }
        }
        catch (System.Exception e) {
            Console.WriteLine("Exception: {0}", e.get_Message());
        }
    } //main
} //MyTypeDemoClass

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft