XmlSerializer typeof(myObject)

问题描述 投票:-1回答:1

有人知道为什么这不起作用?我的错误在这里:new XmlSerializer(typeof(classDTO))

namespace Class.DTOS
{
    public class classDTO
    {
        public int classId { get; set; }
        public string className { get; set; }
        public List<Student> students{ get; set; }
    }

// Student is a class with properties of type string and int

    public class PathFile
    {
        public string Path { get; set; }
    }
} 

其他类别


public void myMethod(classDTO classDto, string path, Stream stream)
{
     XmlSerializer xmlSerializer = new XmlSerializer(typeof(classDTO)); //Here is my error
     //....
}
c# xml-serialization
1个回答
0
投票

到目前为止,代码中一直存在单词class本身,您可以将其用作变量名。

public void myMethod(classDTO **class**, string path, Stream stream)
{
     XmlSerializer xmlSerializer = new XmlSerializer(typeof(classDTO)); //Here is my error
     //....
}

您不能用原始类型(int,string,bool)或类声明变量。使用其他变量名。

© www.soinside.com 2019 - 2024. All rights reserved.