我想设置取决于类型的第一类或第二类的可变结果方法,我的代码有什么问题?
public ActionResult Contact()
{
ViewBag.Message = GetValue(new ClassOne(), "classOne");
return View();
}
public string GetValue<T>(T customClass, string type)
{
if (type == "classOne") return customClass.ClassOneMethod();
else customClass.ClassTwoMethod();
}
class ClassOne
{
public string ClassOneMethod()
{
return "ClassOneMethod";
}
}
class ClassTwo
{
public string ClassTwoMethod()
{
return "ClassTwoMethod";
}
}