草庐IT

TestProperty

全部标签

c# - 使用 XmlSerializer 序列化 char 数据类型

我有一个类,其属性类型为char,如下所示[XmlRoot("Root")]publicclassTestClass{[XmlElement("Test",typeof(char))]publiccharTestProperty{get;set;}}当TestProperty的值为“N”时,如果我序列化TestClass,它将产生以下结果:78但我想要的是有跟随N是否可以不将TestProperty的类型更改为字符串? 最佳答案 不是AFAIK。不过你可以作弊:[XmlIgnore]publiccharTestProperty{ge