Type.IsSealed 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得值,指出 Type 是否宣告為密封。
public:
property bool IsSealed { bool get(); };
public bool IsSealed { get; }
member this.IsSealed : bool
Public ReadOnly Property IsSealed As Boolean
屬性值
如果 true
宣告為密封,則為 Type,否則為 false
。
實作
範例
下列範例會建立類別的實例 sealed
、檢查 IsSealed
屬性,並顯示結果。
using namespace System;
// Declare MyTestClass as sealed.
ref class TestClass sealed{};
int main()
{
TestClass^ testClassInstance = gcnew TestClass;
// Get the type of testClassInstance.
Type^ type = testClassInstance->GetType();
// Get the IsSealed property of the myTestClassInstance.
bool sealed = type->IsSealed;
Console::WriteLine("{0} is sealed: {1}.", type->FullName, sealed);
}
// The example displays the following output:
// TestClass is sealed: True.
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.
Public Class Example
' Declare InnerClass as sealed.
Public NotInheritable Class InnerClass
End Class
Public Shared Sub Main()
Dim inner As New InnerClass()
' Get the type of InnerClass.
Dim innerType As Type = inner.GetType()
' Get the IsSealed property of InnerClass.
Dim sealed As Boolean = innerType.IsSealed
Console.WriteLine("{0} is sealed: {1}.", innerType.FullName, sealed)
End Sub
End Class
' The example displays the following output:
' Example+InnerClass is sealed: True.
備註
如果目前 Type 表示泛型型別的型別參數,則這個屬性一律會傳回 true
。