英語で読む

次の方法で共有


Type.IsSealed プロパティ

定義

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

C#
public bool IsSealed { get; }

プロパティ値

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

実装

次の例では、 クラスのインスタンスを sealed 作成し、 プロパティを IsSealed チェックして結果を表示します。

C#
using System;

 public class Example
 {
     // Declare InnerClass as sealed.
     sealed public class InnerClass
     {
     }

     public static void Main()
     {
          InnerClass inner = new InnerClass();
          // Get the type of InnerClass.
          Type innerType = inner.GetType();
          // Get the IsSealed property of  innerClass.
          bool isSealed = innerType.IsSealed;
          Console.WriteLine("{0} is sealed: {1}.", innerType.FullName, isSealed);
     }
}
// The example displays the following output:
//        Example+InnerClass is sealed: True.

注釈

現在 Type の がジェネリック型の型パラメーターを表す場合、このプロパティは常に を返します true

適用対象

製品 バージョン
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

こちらもご覧ください