好的,这可能是不可能的,但我想使用一个字符串作为函数的参数,并使用该字符串来命名一个类的新实例。使用带有 C# XNA 的 Visual Studios 2010,我尝试使用 google 和 here 搜索解决方案,但也许我没有使用正确的关键字或其他东西。
public void createRace(string raceName, Element element1, Element element2, AbilityScore stat1, AbilityScore stat2, AbilityScore stat3, AbilityScore stat4)
{
Race temp = new Race();
temp.raceName = raceName;
temp.primaryElement = element1;
temp.secondaryElement = element2;
temp.primaryAbility = stat1;
temp.secondaryAbility1 = stat2;
temp.secondaryAbility2 = stat3;
temp.weakAbility = stat4;
}
我希望 Race temp 在命名 Race 的新实例时使用 raceName 而不是 temp,如果不可能,请告诉我,我会找到解决方法。