我是使用接口的新手,所以我有一个问题,对于大多数人来说可能很容易.我目前正在尝试为Windows窗体创建界面.看起来像interface myInterface{//stuff stuff stuff}public partial class myClass : Form, myInterface...

我是使用接口的新手,所以我有一个问题,对于大多数人来说可能很容易.
我目前正在尝试为Windows窗体创建界面.看起来像
interface myInterface
{
//stuff stuff stuff
}
public partial class myClass : Form, myInterface
{
//More stuff stuff stuff. This is the form
}
当我尝试实现它时,问题就来了.如果我实施
myInterface blah = new myClass();
blah.ShowDialog();
现在可以使用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
接口的示例用法是在类之间共享通用方法签名
interface IAnimal
{
int FeetCount();
}
public class Dog : IAnimal
{
int FeetCount()
{
}
}
public class Duck : IAnimal
{
int FeetCount()
{
}
}
织梦狗教程
本文标题为:c#-用Windows窗体实现接口


基础教程推荐
猜你喜欢
- C#使用三层架构开发Winform的详细案例 2023-06-04
- C#实现简易灰度图和酷炫HeatMap热力图winform(附DEMO) 2023-05-10
- C#面向对象编程中依赖反转原则的示例详解 2023-06-27
- Asp.NetCore 3.1demo发布使用Windows服务 2023-09-27
- C#和lua相互调用的方法教程 2022-11-22
- 一个.NET Core开发者的Linux入门学习笔记 2023-09-28
- C#/VB.NET实现HTML转为XML的示例代码 2023-06-15
- C#线程委托实现原理及方法解析 2023-03-09
- WPF通过线程使用ProcessBar的方法详解 2023-01-22
- 详解WPF的InkCanvas选择模式 2023-04-09