I\xc2\xb4m 收到此类错误:
\n\n\n\n\n非静态字段、方法或属性“object.GetType()”需要对象引用
\n
XmlSerializer rd = new XmlSerializer(Roll.GetType())\nRun Code Online (Sandbox Code Playgroud)\n\n班级:
\n\n public class Roll\n{\n public int Code = 0;\n public string Name = "";\n public DateTime Date = DateTime.MinValue;\n}\nRun Code Online (Sandbox Code Playgroud)\n\n如果您需要更多信息,请告诉我。
\n\n谢谢
\n实际上,这意味着您应该使用typeof(Roll)而不是Roll.GetType(). IE,
XmlSerializer rd = new XmlSerializer(typeof(Roll));
Run Code Online (Sandbox Code Playgroud)
从技术上讲,这意味着它Roll是一个类,并且GetType()是该类的有效实例方法(通过继承),但它不是有效的静态方法。因此,您可以调用myRoll.GetType()ifmyRoll是类型的对象实例Roll,但不能调用Roll.GetType().