Why is this cast not possible?

后端 未结 4 541
一个人的身影
一个人的身影 2020-12-06 14:26
interface IFolderOrItem where TFolderOrItem : FolderOrItem {}

abstract class FolderOrItem {}

class Folder : FolderOrItem {}

abstract class It         


        
4条回答
  •  遥遥无期
    2020-12-06 15:01

    The problem is that a cast does not work on the generic arguments, but on the class as a whole. Document inherits from Item, true, but IFolderOrItem< Document> does not inherit from IFolderOrItem< Item>, nor is related with it in any way.

提交回复
热议问题