List<dontknow> Bootstrap = new List<dontknow>() {
new Helper();
new Spells();
new Logic();
new HPSystem();
new Troll();
new MoveSystem(); };
Bootstrap.Init();
我可以在不知道的部分写什么?我初始化的都是类,它们都有 void Init() 我尝试做一个 CustomList 类和 List ,但没有成功。谢谢。如果您有其他方法,可以与我分享。对不起,我还是个新手。
最佳答案
所有的类都必须继承自相同的基类或接口(interface)
public interface IMyThing
{
void Init();
}
public class Helper : IMyThing{ // implementation }
public class Spells : IMyThing{ // implementation }
//etc.
也可以是基类,例如 MyThingBase
然后使用列表的接口(interface)/基类
List<IMyThing> Bootstrap = new List<IMyThing>() {
new Helper();
new Spells();
new Logic();
new HPSystem();
new Troll();
new MoveSystem(); };
然后您需要枚举列表以调用 Init
BootStrap.ForEach(x => x.Init());
关于c# - 如何初始化加载程序列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40317371/