问题描述
我有多个工厂接受一个 int 并返回一个 Creature 类型的对象:
public static Func<int,Creature>[] ForestEnemyFactory1 = new Func<int,Creature>[]
{
(level) => (Creature) new Spider(level),(level) => (Creature) new Ogre(level),};
public static Func<int,Creature>[] ForestEnemyFactory2 = new Func<int,Creature>[]
{
(level) => (Creature) new ArmourBug(level),(level) => (Creature) new GlowBug(level)
};
if (...) {
Enemy1 = ForestEnemyFactory1[x](y);
else
现在我想让函数总是调用同一个委托,并决定在其他地方调用哪个。
delegate Del = ...
Enemy1 = delegate (int positionInArray,int level)
然后在别处定义:
if (...){
delegate = ForestEnemyFactory2;
但无论我如何尝试,我都无法找到如何定义委托并让他接受其中一个工厂的解决方案。有人可以帮忙吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)