1.选中需要加注释的,
添加注释:CTRL + SHIFT +/
撤销注释:CTRL + SHIFT +\
2.第二种方式:在需要加注释的本行,
添加/撤销注释:CTRL + SHIFT +C
public class Program{
static void Main(string[] args)
{
XmlSerializer ser = new XmlSerializer(typeof(Mail))
using (FileStream fs = new FileStream(@"C:\test.xml", FileMode.OpenOrCreate))
{
using (XmlWriter writer = XmlWriter.Create(fs))
{
writer.WriteComment("This is a letter")
ser.Serialize(writer, new Mail() { Date = new DateTime(2006, 1, 1), To = "Li", From = "Zhang", Title = "Hello", Body = "how are you?" })
}
}
}
[Serializable]
[XmlRoot(ElementName = "mail")]
public class Mail
{
[XmlAttribute(AttributeName = "date")]
public DateTime Date { get set }
[XmlElement(ElementName = "to")]
public string To { get set }
[XmlElement(ElementName = "from")]
public string From { get set }
[XmlElement(ElementName = "body")]
public string Body { get set }
[XmlElement(ElementName = "title")]
public string Title { get set }
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)