Force subclasses of an interface to implement ToString

后端 未结 7 2122
猫巷女王i
猫巷女王i 2020-12-28 11:19

Say I have an interface IFoo and I want all subclasses of IFoo to override Object\'s ToString method. Is this possible?

Simpl

7条回答
  •  孤独总比滥情好
    2020-12-28 12:02

    I don't believe you can do it with an interface. You can use an abstract base class though:

    public abstract class Base
    {
        public abstract override string ToString(); 
    }
    

提交回复
热议问题