Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
IsPrimitiveImpl Method
Collapse the table of content
Expand the table of content

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 MustOverride Function IsPrimitiveImpl As Boolean

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.

Imports System
Imports System.Reflection
Imports Microsoft.VisualBasic
Public Class MyTypeDelegatorClass
    Inherits TypeDelegator
    Public myElementType As String = Nothing 
    Private myType As Type = Nothing 
    Public Sub New(ByVal myType As Type)
        Me.myType = myType
    End Sub 'New 
    ' Override the IsPrimitiveImpl method. 
    Protected Overrides Function IsPrimitiveImpl() As Boolean 
        ' Determine whether the type is a primitive type. 
        If myType.IsPrimitive Then
            myElementType = "primitive" 
            Return True 
        End If 
        Return False 
    End Function 'IsPrimitiveImpl
End Class 'MyTypeDelegatorClass
Public Class MyTypeDemoClass
    Public Shared Sub Main()
            Console.WriteLine("Determine whether int is a primitive type.")
            Dim myType As MyTypeDelegatorClass
            myType = New MyTypeDelegatorClass(GetType(Integer))
            ' Determine whether int is a primitive type. 
            If myType.IsPrimitive Then
                Console.WriteLine(GetType(Integer).ToString() + " is a primitive type.")
                Console.WriteLine(GetType(Integer).ToString() + " is not a primitive type.")
            End If
            Console.WriteLine(ControlChars.NewLine + "Determine whether string is a primitive type.")
            myType = New MyTypeDelegatorClass(GetType(String))
            ' Determine whether string is a primitive type. 
            If myType.IsPrimitive Then
                Console.WriteLine(GetType(String).ToString() + " is a primitive type.")
                Console.WriteLine(GetType(String).ToString() + " is not a primitive type.")
            End If 
        Catch e As Exception
            Console.WriteLine("Exception: {0}", e.Message.ToString())
        End Try 
    End Sub 'Main
End Class 'MyTypeDemoClass

.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

XNA Framework

Supported in: 3.0, 2.0, 1.0

.NET for Windows Phone apps

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

Portable Class Library

Supported in: Portable Class Library
© 2015 Microsoft