Export (0) Print
Expand All
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)

'Declaration
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)
        MyBase.New(myType)
        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()
        Try
            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.")
            Else
                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.")
            Else
                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.5.2, 4.5.1, 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 8, Silverlight 8.1

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.

Show:
© 2014 Microsoft