我们可以创建接口保护或私有,如果是,然后如何用类实现它们? [英] Can we create interface protected or private if yes then how they will be implemented with a class?
本文介绍了我们可以创建接口保护或私有,如果是,然后如何用类实现它们?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们可以创建接口保护或私有,如果是,那么它们将如何用类实现?
Can we create interface protected or private if yes then how they will be implemented with a class?
推荐答案
是。
通常的规则适用,就好像您在现有类中声明一个类:
Yes.
The usual rules apply as if you were declaring a class as within an existing class:
public class MyOuterClass
{
private void butCreate_Click(object sender, EventArgs e)
{
MyInterface mc = new MyClass();
}
public class MyClass : MyInterface
{
public void MyMethod()
{
throw new NotImplementedException();
}
}
private interface MyInterface
{
void MyMethod();
}
}
可以通过外部类中定义的任何类访问该接口。
The interface can be accessed by any classes defined within the outer class.
这篇关于我们可以创建接口保护或私有,如果是,然后如何用类实现它们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文