有没有你不能定义一个方法或接口的访问修饰符理由吗? [英] Is there a reason you can not define the access modifier on a method or in an interface?

查看:218
本文介绍了有没有你不能定义一个方法或接口的访问修饰符理由吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

方法的可见性的责任被转移到实现该接口的类。

The responsibility of the visibility of a method is relegated to the class that implements the interface.

public interface IMyInterface
{
  bool GetMyInfo(string request);
}

在C#中设置访问修饰符公共,私人或方法GetMyInfo之前保护()生成以下错误:修饰符'私人'是无效的此项目

In C# set access modifier public, private or protected before the method GetMyInfo() generates the following error: The modifier 'private' is not valid for this item.

是否有你不能定义一个方法或接口的访问修饰符的理由?

Is there a reason you can not define the access modifier on a method or in an interface?

(问题已经问法语的这里

推荐答案

该接口定义了一个对象,并调用其成员的客户之间的合同。一个私有方法不能被任何其他对象进行访问,因此没有意义,将其添加到界面上。接口的所有成员都被视为公共出于这个原因。

The interface defines a contract between an object and clients that call its members. A private method cannot be accessed by any other objects so it doesn't make sense to add it to the interface. All members of an interface are considered public for this reason.

这篇关于有没有你不能定义一个方法或接口的访问修饰符理由吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆