【发布时间】:2016-01-17 15:44:10
【问题描述】:
这更像是一个理论问题,但我想知道在表单中传递信息的最佳方式是什么。我会解释我的问题:
我有我的 Mainform 类来管理整个应用程序:
public class Mainform : Form
{
private static AddressBook _addressbook = new AddressBook();
private static TemplateManager _templateManager = new TemplateManager();
/*...*/
}
此外,我还有另一个由Mainform 创建的类:
public partial class TemplateLists : Form
{
//To be filled with Mainform's information.
private List<Template> _genericTemplates;
private Client _clientToFill;
//In this case, I decided to pass the information through the constructor.
public TemplateLists(List<Template> genericTemplates, Client client)
{
InitializeComponent();
_genericTemplates = genericTemplates;
_clientToFill = client;
}
}
问题是,为了让TemplateLists 接收_genericTemplates 信息,我不知道最好是通过构造函数、方法还是公共属性来完成,为什么。无论如何,我都知道如何实现它们,但我不知道哪个是最好的,我没有任何理由选择一个而不是另一个。
【问题讨论】: