Type.IsSealed 属性

定义

获取一个值,该值指示 Type 是否声明为密封的。

C#
public bool IsSealed { get; }

属性值

如果 true 被声明为密封的,则为 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

另请参阅