我有一个HotDog类作为Food类的一个子类。(“Child Class”是“Parent class”)
public class HotDog : Food
{
public HotDog() : base ("hotdog", new string[] { "bread", "meat"}, new int[] { 1, 1 }, 0.7)
{
}
}
我试图做到这一点
Type t = typeof("HotDog");
if (t is Food) {
Food f = (Food)Food.CreateOne (t);
}
这是我CreateOne方法
public static Consumables CreateOne (Type t)
{
return (Consumables)Activator.CreateInstance (t);
}
但我得到的t是所提供的食品种类的从来都不是错误,以便里面的代码是不可达。任何想法这个东西有什么问题,我该如何解决它?
'Hot Dog'!='HotDog'。 – 2014-10-08 06:31:48