好的,所以这真的很厉害.我有一个私人会员,我想使用它到Form2.我已经做了一个公共静态方法,所以我可以把该成员加入到Form2中.
这是我的代码:
private static AppController appController; private BreadRepository breadRep; private CakeRepository cakeRep; private SandwichRepository sandwichRep; public Form1() { InitializeComponent(); breadRep = new BreadRepository(); cakeRep = new CakeRepository(); sandwichRep = new SandwichRepository(); appController = new AppController(breadRep,sandwichRep,cakeRep); } public static AppController getController() { return appController; }
我试图使FormController从Form1公开,但我得到更多的错误.现在我得到这个:
Inconsistent accessibility: return type ‘exemplu_map.controller.AppController’ is less accessible than method ‘exemplu_map.Form1.getController()’
Any ideas ?
更新:
这是我的AppController类:
class AppController { private BreadRepository breadRep; private SandwichRepository sandwichRep; private CakeRepository cakeRep; public AppController(BreadRepository breadRep,SandwichRepository sandwichRep,CakeRepository cakeRep) { this.breadRep = breadRep; this.sandwichRep = sandwichRep; this.cakeRep = cakeRep; } public void writeToFile(String file) { StreamWriter wr = new StreamWriter(file); String writeMe = ""; foreach(Bread e in breadRep.getAll()) { writeMe = writeMe + e.getAll() + "\n"; } foreach (Sandwich e in sandwichRep.getAll()) { writeMe = writeMe + e.getAll() + "\n"; } foreach (Cake e in cakeRep.getAll()) { writeMe = writeMe + e.getAll() + "\n"; } wr.Write(writeMe); wr.Close(); } }
我已将AppController更改为public,但是我再次收到更多错误.同样的错误,但对于breadRep,cakeRep,sandwichRep.