例如,我有一个名为 Clothing 的类,它继承自 Product 的抽象类。
public class Clothing : Product
{
public bool IsInSeason {get; set;}
public string Material {get; set; }
public Decimal IsFeatured { get; set; }
}
Edit:在函数中,我如何能够传递字符串“Clothing”并返回类的类型?
ReturnTypeOfClassBasedOffOfString(string class)
{
// ...
}
Use 类型.GetType(字符串) http://msdn.microsoft.com/en-us/library/w3f99sx1.aspx
请注意,有时类名还不够。有时您需要提供装配合格名称 http://msdn.microsoft.com/en-us/library/system.type.assemblyqualifiedname.aspx
“如果该类型位于当前正在执行的程序集中或 Mscorlib.dll 中,则提供由其命名空间限定的类型名称就足够了。”
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)