如何初始化Loader List

本文关键字:List Loader 初始化 | 更新日期: 2023-09-27 18:15:32

   List<dontknow> Bootstrap = new List<dontknow>()  {
        new Helper();
        new Spells();
        new Logic();
        new HPSystem();
        new Troll();
        new MoveSystem(); };
        Bootstrap.Init();

对于不知道的部分我能写些什么?我所初始化的都是类,它们都有void Init()我试着做一个CustomList类和列表,它没有工作出来。谢谢。如果你有其他方法,可以和我分享。对不起,我还是个新手。

如何初始化Loader List

所有的类必须继承自相同的基类或接口

public interface IMyThing
{
    void Init();
}
public class Helper : IMyThing{ // implementation }
public class Spells : IMyThing{ // implementation }
//etc.

也可以是一个基类,如MyThingBase

然后为列表使用接口/基类

List<IMyThing> Bootstrap = new List<IMyThing>()  {
        new Helper();
        new Spells();
        new Logic();
        new HPSystem();
        new Troll();
        new MoveSystem(); };

然后需要枚举列表以调用Init

BootStrap.ForEach(x => x.Init());
相关文章: