Dart查看Instance of type是否继承自其他类型

时间:2016-12-13 18:03:22

标签: dart

 var fileCount = Directory.EnumerateFiles(@"C:\").Count();
 if (fileCount == 0)
    Console.WriteLine("Empty");
 else
    Console.WriteLine("Not Empty");

您可以使用class a {/*code*/} class b extends a {/*more code*/} void main() { b c = new b(); print(c.runtimeType == a); //type == inheritedType //or print(c.runtimeType inherits a); //operator for inheritance //or print(c inherits a); //other operator for inheritance } type == inheriting typetype inherits other type吗? 有没有办法做这样的事情? 因为我还没有找到任何办法。

1 个答案:

答案 0 :(得分:2)

使用is

你可以c is a。请注意,new a() is a也是true。如果您真的想知道实例是否是另一种类型的子类型,您可能会问c is a && c.runtimeType != a