Export (0) Print
Expand All

Type.IsPrimitive Property

Gets a value indicating whether the Type is one of the primitive types.

[Visual Basic]
Public ReadOnly Property IsPrimitive As Boolean
[C#]
public bool IsPrimitive {get;}
[C++]
public: __property bool get_IsPrimitive();
[JScript]
public function get IsPrimitive() : Boolean;

Property Value

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

Remarks

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

Example

[Visual Basic, C#, C++] The following example demonstrates the IsContextful, IsMarshalByRef, and IsPrimitive properties of the Type class. It checks whether the given type can be hosted in the context, whether it can be marshalled by reference, and whether the type is a primitive data type.

[Visual Basic] 
Imports System
Imports System.Runtime.Remoting.Contexts
Imports Microsoft.VisualBasic
Public Class MyContextBoundClass
    Inherits ContextBoundObject
    Public myString As String = "This class demonstrates the IsContextful, IsMarshalByRef, and IsPrimitive properties."
End Class 'MyContextBoundClass
Public Class MyTypeDemoClass
    Public Shared Sub Main()
        Try
            ' Determine whether the types can be hosted in a Context.
            Console.WriteLine("The Contextful property for the {0} type is {1}.", GetType(MyTypeDemoClass).Name, GetType(MyTypeDemoClass).IsContextful.ToString())
            Console.WriteLine("The Contextful property for the {0} type is {1}.", GetType(MyContextBoundClass).Name, GetType(MyContextBoundClass).IsContextful.ToString())
            ' Determine whether the types are marshalled by reference.
            Console.WriteLine("The MarshalByRef property of {0} is {1}.", GetType(MyTypeDemoClass).Name, GetType(MyTypeDemoClass).IsMarshalByRef.ToString())
            Console.WriteLine("The MarshalByRef property of {0} is {1}.", GetType(MyContextBoundClass).Name, GetType(MyContextBoundClass).IsMarshalByRef.ToString())
            ' Determine whether the types are primitive datatypes.
            Console.WriteLine("Is {0} a primitive data type? {1}.", GetType(Integer).Name, GetType(Integer).IsPrimitive.ToString())
            Console.WriteLine("Is {0} a primitive data type? {1}.", GetType(String).Name, GetType(String).IsPrimitive.ToString())
        Catch e As Exception
            Console.WriteLine("An exception occurred: " + e.Message.ToString())
        End Try
    End Sub 'Main
End Class 'MyTypeDemoClass

[C#] 
using System;
using System.Runtime.Remoting.Contexts;
public class MyContextBoundClass: ContextBoundObject
{
    public string myString = "This class demonstrates the IsContextful, IsMarshalByRef, and IsPrimitive properties.";
}
public class MyTypeDemoClass
{
    public static void Main()
    {
        try
        {
            // Determine whether the types can be hosted in a Context.
            Console.WriteLine ("The IsContextful property for the {0} type is {1}.", typeof(MyTypeDemoClass).Name, typeof(MyTypeDemoClass).IsContextful);
            Console.WriteLine ("The IsContextful property for the {0} type is {1}.", typeof(MyContextBoundClass).Name, typeof(MyContextBoundClass).IsContextful);

            // Determine whether the types are marshalled by reference.
            Console.WriteLine ("The MarshalByRef property of {0} is {1}.", typeof(MyTypeDemoClass).Name, typeof(MyTypeDemoClass).IsMarshalByRef);
            Console.WriteLine ("The MarshalByRef property of {0} is {1}.", typeof(MyContextBoundClass).Name, typeof(MyContextBoundClass).IsMarshalByRef);
            
            // Determine whether the types are primitive datatypes.
            Console.WriteLine ("Is {0} is a primitive data type? {1}.", typeof(int).Name, typeof(int).IsPrimitive);
            Console.WriteLine ("Is {0} a primitive data type? {1}.", typeof(string).Name, typeof(string).IsPrimitive);
        } 
        catch (Exception e)
        {
            Console.WriteLine("An exception occurred: " + e.Message);
        }
    }
}

[C++] 
#using <mscorlib.dll>

using namespace System;
using namespace System::Runtime::Remoting::Contexts;
public __gc class MyContextBoundClass : public ContextBoundObject {
public:
   String* myString;
};
public __gc class MyTypeDemoClass {
public:
   void Demo() {
      try {
         // Determine whether the types can be hosted in a Context.
         Console::WriteLine (S"The IsContextful property for the {0} type is {1}.", __typeof(MyTypeDemoClass)->Name,__box( __typeof(MyTypeDemoClass)->IsContextful));
         Console::WriteLine (S"The IsContextful property for the {0} type is {1}.", __typeof(MyContextBoundClass)->Name, __box(__typeof(MyContextBoundClass)->IsContextful));

         // Determine whether the types are marshalled by reference.
         Console::WriteLine (S"The MarshalByRef property of {0} is {1}.", __typeof(MyTypeDemoClass)->Name,__box( __typeof(MyTypeDemoClass)->IsMarshalByRef));
         Console::WriteLine (S"The MarshalByRef property of {0} is {1}.", __typeof(MyContextBoundClass)->Name,__box( __typeof(MyContextBoundClass)->IsMarshalByRef));

         // Determine whether the types are primitive datatypes.
         Console::WriteLine (S"Is {0} is a primitive data type? {1}.", __typeof(int)->Name,__box( __typeof(int)->IsPrimitive));
         Console::WriteLine (S"Is {0} a primitive data type? {1}.", __typeof(String)->Name, __box(__typeof(String)->IsPrimitive));
      } catch (Exception* e) {
         Console::WriteLine(S"An exception occurred: {0}", e->Message);
      }
   }
};

int main()
{
   MyTypeDemoClass* mtdc = new MyTypeDemoClass();
   mtdc->Demo();
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

Type Class | Type Members | System Namespace | Boolean | Byte | SByte | Int16 | UInt16 | Int32 | UInt32 | Int64 | UInt64 | Char | Double | Single | IsPrimitiveImpl

Show:
© 2014 Microsoft