Export (0) Print
Expand All

Type.IsSealed Property

Gets a value indicating whether the Type is declared sealed.

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

Property Value

true if the Type is declared sealed; otherwise, false.

Example

[Visual Basic, C#, C++] The following example creates an instance of a sealed (NotInheritable in Visual Basic) class, checks for the IsSealed property, and displays the result.

[Visual Basic] 
Imports System
Imports Microsoft.VisualBasic
Namespace SystemType
    Public Class [MyClass]
        ' Declare MyTestClass as sealed.
        Public NotInheritable Class MyTestClass
        End Class 'MyTestClass
        Public Shared Sub Main()
            Try
                Dim myBool As Boolean = False
                Dim myTestClassInstance As New MyTestClass()
                ' Get the type of myTestClassInstance.
                Dim myType As Type = myTestClassInstance.GetType()
                ' Get the IsSealed property of myTestClassInstance.
                myBool = myType.IsSealed
                Console.WriteLine(ControlChars.Cr + "Is {0} sealed? {1}.", myType.FullName, myBool.ToString())
            Catch e As Exception
                Console.WriteLine(ControlChars.Cr + "An exception occurred: {0}", e.Message.ToString())
            End Try
        End Sub 'Main
    End Class '[MyClass] 
End Namespace 'SystemType

[C#] 
using System;
namespace SystemType
{
    public class MyClass
    {
        // Declare MyTestClass as sealed.
        sealed public class MyTestClass
        {
        }
        public static void Main(string []args)
        {
            try
            {
                bool myBool = false;
                MyTestClass myTestClassInstance = new MyTestClass();
                // Get the type of myTestClassInstance.
                Type myType = myTestClassInstance.GetType();
                // Get the IsSealed property of the myTestClassInstance.
                myBool = myType.IsSealed;
                Console.WriteLine("\nIs {0} sealed? {1}.", myType.FullName, myBool.ToString());
            }
            catch (Exception e)
            {
                Console.WriteLine("\nAn exception occurred: {0}",e.Message);
            }
        }
    }
}

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

using namespace System;

public __gc class MyClass {
   // Declare MyTestClass as sealed.
public:
   __sealed __gc class MyTestClass {
   };
   static void Test() {
      try {
         bool myBool = false;
         MyTestClass* myTestClassInstance = new MyTestClass();
         // Get the type of myTestClassInstance.
         Type*  myType = myTestClassInstance->GetType();
         // Get the IsSealed property of the myTestClassInstance.
         myBool = myType->IsSealed;
         Console::WriteLine(S"\nIs {0} sealed? {1}.", myType->FullName, __box( myBool));
      } catch (Exception* e) {
         Console::WriteLine(S"\nAn exception occurred: {0}", e->Message);
      }
   }
};

int main(){
   MyClass::Test();
}

[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 | TypeAttributes

Show:
© 2014 Microsoft