快点来~我想转换 ToString 这样我就可以用那个类型替换变量了~public void ChangePanel<T>(T Action){ FieldInfo Field = T.GetField(T.toString); Field.SetValue(SomeObject, Action);}另外请让我知道是否有更好的方法来做到这一点!!编辑:仅供引用 SomeObject 中的变量与类型同名 最佳答案 您可以使用 typeof Keyword 获取 Type 实例,使用 Type.Name Property 获取类型名称。public void ChangePanel<T>(T action){ Type typeOfObject = someObject.GetType(); Type typeOfAction = typeof(T); FieldInfo field = typeOfObject.GetField(typeOfAction.Name); field.SetValue(someObject, action);}关于C# 泛型 : Can you convert <T> ToString?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18969699/