Type.IsValueTypeImpl Method
Implements the IsValueType property and determines whether the Type is a value type; that is, not a class or an interface.
[Visual Basic] Protected Overridable Function IsValueTypeImpl() As Boolean [C#] protected virtual bool IsValueTypeImpl(); [C++] protected: virtual bool IsValueTypeImpl(); [JScript] protected function IsValueTypeImpl() : Boolean;
Return Value
true if the Type is a value type; otherwise, false.
Remarks
Value types describe values that are represented as sequences of bits; value types are not classes or interfaces. These are referred to as "structs" in some programming languages. Enums are value types.
Example
[Visual Basic] Imports System Imports System.Reflection Imports Microsoft.VisualBasic Public Class MyTypeDelegator Inherits TypeDelegator Public myElementType As String = Nothing Private myType As Type = Nothing Public Sub New(myType As Type) MyBase.New(myType) Me.myType = myType End Sub 'New ' Override the IsValueTypeImpl() method of the Type class. Protected Overrides Function IsValueTypeImpl() As Boolean ' Determine whether the type is a value type. If myType.IsValueType Then myElementType = "value" Return True End If ' The type is not a value type. Return False End Function 'IsValueTypeImpl End Class 'MyTypeDelegator Public Class Type_IsValueTypeImpl Public Class MyClass1 End Class 'MyClass1 Public Shared Sub Main() Try Dim myInt As Integer = 0 Dim myClass1 As New MyClass1() Dim myType As New MyTypeDelegator(myInt.GetType()) Console.WriteLine(ControlChars.NewLine + "Determine whether a variable refers to a value type." + ControlChars.NewLine) ' Determine whether 'myType' is a value type. If myType.IsValueType Then Console.WriteLine(ControlChars.NewLine + "'myInt' is a {0} type.", myType.myElementType) Else Console.WriteLine(ControlChars.NewLine + "'myInt' is not a value type.") End If myType = New MyTypeDelegator(myClass1.GetType()) ' Determine whether 'myType' is a value type. If myType.IsValueType Then Console.WriteLine(ControlChars.NewLine + "'myClass1' is a {0} type.", myType.myElementType) Else Console.WriteLine(ControlChars.NewLine + "'myClass1' is not a value type.") End If Catch e As Exception Console.WriteLine(ControlChars.NewLine + "The following exception is raised:" + e.Message.ToString()) End Try End Sub 'Main End Class 'Type_IsValueTypeImpl [C#] using System; using System.Reflection; public class MyTypeDelegator : TypeDelegator { public string myElementType = null; private Type myType = null ; public MyTypeDelegator(Type myType) : base(myType) { this.myType = myType; } // Override 'IsValueTypeImpl()' method of 'Type' class. protected override bool IsValueTypeImpl() { // Determine whether the type is a value type. if(myType.IsValueType) { myElementType = "value"; return true; } // The type is not value type. return false; } } public class Type_IsValueTypeImpl { public class MyClass { } public static void Main() { try { int myInt = 0 ; MyClass myClass = new MyClass (); MyTypeDelegator myType = new MyTypeDelegator(myInt.GetType()); Console.WriteLine("\nCheck whether a variable refers to a value type.\n"); // Determine whether 'myType' is a value type. if( myType.IsValueType) Console.WriteLine("\n'myInt' is a {0} type.", myType.myElementType); else Console.WriteLine("\n'myInt' is not a value type."); myType = new MyTypeDelegator(myClass.GetType()); // Determine whether 'myType' is a value type. if( myType.IsValueType) Console.WriteLine("\n'myClass' is a {0} type.", myType.myElementType); else Console.WriteLine("\n'myClass' is not a value type."); } catch( Exception e ) { Console.WriteLine("\nThe following exception is raised:" +e.Message); } } } [C++] #using <mscorlib.dll> using namespace System; using namespace System::Reflection; public __gc class MyTypeDelegator : public TypeDelegator { public: String* myElementType; private: Type* myType; public: MyTypeDelegator(Type* myType) : TypeDelegator(myType) { this->myType = myType; } // Override 'IsValueTypeImpl()' method of 'Type' class. protected: bool IsValueTypeImpl() { // Determine whether the type is a value type. if (myType->IsValueType) { myElementType = S"value"; return true; } // The type is not value type. return false; } }; public __gc class MyClass { }; int main() { try { int myInt = 0 ; MyClass* myClass = new MyClass (); MyTypeDelegator* myType = new MyTypeDelegator( __box(myInt)->GetType()); Console::WriteLine(S"\nCheck whether a variable refers to a value type.\n"); // Determine whether 'myType' is a value type. if (myType->IsValueType) Console::WriteLine(S"\n'myInt' is a {0} type.", myType->myElementType); else Console::WriteLine(S"\n'myInt' is not a value type."); myType = new MyTypeDelegator(myClass->GetType()); // Determine whether 'myType' is a value type. if (myType->IsValueType) Console::WriteLine(S"\n'myClass' is a {0} type.", myType->myElementType); else Console::WriteLine(S"\n'myClass' is not a value type."); } catch (Exception* e) { Console::WriteLine(S"\nThe following exception is raised: {0}", e->Message); } }
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
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
See Also
Type Class | Type Members | System Namespace | TypeAttributes | IsClass | IsInterface | ValueType | IsValueType