Type.IsSealed プロパティ
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
Type が sealed として宣言されているかどうかを示す値を取得します。
public:
property bool IsSealed { bool get(); };
C#
public bool IsSealed { get; }
member this.IsSealed : bool
Public ReadOnly Property IsSealed As Boolean
true
が sealed として宣言されている場合は 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.
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.
module Example
// Declare InnerClass as sealed.
[<Sealed>]
type InnerClass() = class end
let inner = InnerClass()
// Get the type of InnerClass.
let innerType = inner.GetType()
// Get the IsSealed property of innerClass.
let isSealed = innerType.IsSealed
printfn $"{innerType.FullName} is sealed: {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
。
製品 | バージョン |
---|---|
.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 |
GitHub で Microsoft と共同作業する
このコンテンツのソースは GitHub にあります。そこで、issue や pull request を作成および確認することもできます。 詳細については、共同作成者ガイドを参照してください。
.NET に関するフィードバック
.NET はオープンソース プロジェクトです。 フィードバックを提供するにはリンクを選択します。