简体   繁体   English

C#XMLSerializer构造函数

[英]C# XMLSerializer Constructor

I have this code but i don't know what should be in the constructor Klant() . 我有这段代码,但我不知道构造函数Klant()应该包含什么。 What should come here so the field 'voornaam' comes in the XML? XML中的“ voornaam”字段应该出现在这里?

public static void SchrijfKlanten(Klant klant, string pad) {
    using (FileStream file = File.Open(pad, FileMode.OpenOrCreate)) {
    XmlSerializer xml = new XmlSerializer(klant.GetType()); //THIS LINE
    xml.Serialize(file, klant);
    }
}

public class Klant {
    string voornaam;

    public Klant(){
        //Here
    }

Your field should be a public property. 您的字段应该是公共财产。 Other than that, it should work fine even without any constructor. 除此之外,即使没有任何构造函数,它也可以正常工作。

public class Klant 
{
    public string Voornaam { get; set; }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM