use*_*103 5 c# interface winforms
我是使用接口的新手,所以我有一个对你们大多数人来说可能很容易的问题。
我目前正在尝试为 Windows 窗体制作一个界面。它看起来像
interface myInterface
{
//stuff stuff stuff
}
public partial class myClass : Form, myInterface
{
//More stuff stuff stuff. This is the form
}
Run Code Online (Sandbox Code Playgroud)
当我尝试实施它时,问题就来了。如果我实施
myInterface blah = new myClass();
blah.ShowDialog();
Run Code Online (Sandbox Code Playgroud)
ShowDialog() 函数现在可供它使用。这是有道理的 - myInterface 是一个接口,而不是一个表单......但我很好奇我应该如何使用 Windows 表单实现接口,或者它是否甚至是一个可行的选择。
有没有人对我应该如何去做有任何建议?
谢谢!
这似乎是一个关于如何正确公开类成员的问题。
internal - Access to a method/class is restricted to the application
public - Access is not restricted
private - Access is restricted to the current class (methods)
protected - Access is restricted to the current class and its inherited classes
Run Code Online (Sandbox Code Playgroud)
接口的一个示例是在类之间共享通用方法签名
interface IAnimal
{
int FeetCount();
}
public class Dog : IAnimal
{
int FeetCount()
{
}
}
public class Duck : IAnimal
{
int FeetCount()
{
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13714 次 |
| 最近记录: |