C# Type IsPrimitiveImpl

Description

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

Syntax

Type.IsPrimitiveImpl has the following syntax.


protected abstract bool IsPrimitiveImpl()

Returns

Type.IsPrimitiveImpl method returns true if the Type is one of the primitive types; otherwise, false.

Example

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


/*from  w w  w.  j a v  a 2s.c  om*/

using System;
using System.Reflection;
public class MyTypeDelegatorClass : TypeDelegator
{
    public string myElementType = null;
    private Type myType = null ; 
    public MyTypeDelegatorClass(Type myType) : base(myType)
    {
        this.myType = myType;
    }
    protected override bool IsPrimitiveImpl()
    {
        if(myType.IsPrimitive)
        { 
            myElementType = "primitive";
            return true;
        }
        return false;
    }
}
public class MyTypeDemoClass
{
    public static void Main()
    {
        MyTypeDelegatorClass myType;
        myType = new MyTypeDelegatorClass(typeof(int));
        Console.WriteLine(myType.IsPrimitive);
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version