次の方法で共有


Type.IsSealed プロパティ

Type が sealed として宣言されているかどうかを示す値を取得します。

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

プロパティ値

Type が sealed として宣言されている場合は true 。それ以外の場合は false

使用例

[Visual Basic, C#, C++] シール (Visual Basic では NotInheritable) クラスのインスタンスを作成し、 IsSealed プロパティをチェックして、結果を表示する例を次に示します。

 
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] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET, Common Language Infrastructure (CLI) Standard

参照

Type クラス | Type メンバ | System 名前空間 | TypeAttributes