本文整理汇总了C#中System.Type.IsSealed属性的典型用法代码示例。如果您正苦于以下问题:C# Type.IsSealed属性的具体用法?C# Type.IsSealed怎么用?C# Type.IsSealed使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Type
的用法示例。
在下文中一共展示了Type.IsSealed属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
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);
}
}
输出:
Example+InnerClass is sealed: True.
示例2: MethodA
//引入命名空间
using System;
using System.Reflection;
public interface IFaceOne
{
void MethodA();
}
public interface IFaceTwo
{
void MethodB();
}
public class MyClass: IFaceOne, IFaceTwo
{
public enum MyNestedEnum{}
public int myIntField;
public string myStringField;
public void myMethod(int p1, string p2)
{
}
public int MyProp
{
get { return myIntField; }
set { myIntField = value; }
}
void IFaceOne.MethodA(){}
void IFaceTwo.MethodB(){}
}
public class MainClass
{
public static void Main(string[] args)
{
MyClass f = new MyClass();
Type t = f.GetType();
Console.WriteLine("Full name is: {0}", t.FullName);
Console.WriteLine("Base is: {0}", t.BaseType);
Console.WriteLine("Is it abstract? {0}", t.IsAbstract);
Console.WriteLine("Is it a COM object? {0}", t.IsCOMObject);
Console.WriteLine("Is it sealed? {0}", t.IsSealed);
Console.WriteLine("Is it a class? {0}", t.IsClass);
}
}