为什么C#不允许静态方法实现接口?

为什么C#不允许静态方法实现接口?

为什么C#是这样设计的?

据我所知,接口只描述行为,并用于描述实现某些行为的类的契约义务。

如果类希望在共享方法中实现该行为,那么它们为什么不应该实现呢?

下面是我所想到的一个例子:

// These items will be displayed in a list on the screen.public interface IListItem {
  string ScreenName();
  ...}public class Animal: IListItem {
    // All animals will be called "Animal".
    public static string ScreenName() {
        return "Animal";
    }....}public class Person: IListItem {

    private string name;

    // All persons will be called by their individual names.
    public string ScreenName() {
        return name;
    }

    ....

 }


慕田峪7331174
浏览 1421回答 3
3回答
打开App,查看更多内容
随时随地看视频慕课网APP