为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

慕田峪7331174 2019-07-10 10:19:59
为什么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;     }     ....  }
查看完整描述

3 回答

  • 3 回答
  • 0 关注
  • 1417 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信