using System;
public interface IMyIfc {}
public interface IDerived : IMyIfc {}
public class Class1 : IMyIfc {}
public class MyDerivedClass : Class1 {}
class IsSubclassTest
{
public static void Main()
{
Type imyifcType = typeof(IMyIfc);
Type imyderivedType = typeof(IDerived);
Class1 mc = new Class1();
Type mcType = mc.GetType();
Class1 mdc = new MyDerivedClass();
Type mdcType = mdc.GetType();
int [] array = new int [10];
Type arrayOfIntsType = array.GetType();
Type arrayType = typeof(Array);
Console.WriteLine("Array is derived class of int[]? {0}", arrayType.IsSubclassOf(arrayOfIntsType));
Console.WriteLine("int [] is derived class of Array? {0}", arrayOfIntsType.IsSubclassOf(arrayType));
Console.WriteLine("IMyIfc is derived class of IDerived? {0}", imyifcType.IsSubclassOf(imyderivedType));
Console.WriteLine("myclass is derived class of Class1? {0}", mcType.IsSubclassOf(mcType));
Console.WriteLine("myderivedclass is derived class of Class1? {0}", mdcType.IsSubclassOf(mcType));
}
}
public interface IMyIfc {}
public interface IDerived : IMyIfc {}
public class Class1 : IMyIfc {}
public class MyDerivedClass : Class1 {}
class IsSubclassTest
{
public static void Main()
{
Type imyifcType = typeof(IMyIfc);
Type imyderivedType = typeof(IDerived);
Class1 mc = new Class1();
Type mcType = mc.GetType();
Class1 mdc = new MyDerivedClass();
Type mdcType = mdc.GetType();
int [] array = new int [10];
Type arrayOfIntsType = array.GetType();
Type arrayType = typeof(Array);
Console.WriteLine("Array is derived class of int[]? {0}", arrayType.IsSubclassOf(arrayOfIntsType));
Console.WriteLine("int [] is derived class of Array? {0}", arrayOfIntsType.IsSubclassOf(arrayType));
Console.WriteLine("IMyIfc is derived class of IDerived? {0}", imyifcType.IsSubclassOf(imyderivedType));
Console.WriteLine("myclass is derived class of Class1? {0}", mcType.IsSubclassOf(mcType));
Console.WriteLine("myderivedclass is derived class of Class1? {0}", mdcType.IsSubclassOf(mcType));
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货