class1.cs
来自「C#开发教程 由浅入深 配有实例 是初学者的好帮手」· CS 代码 · 共 42 行
CS
42 行
using System;
using System.IO;
using System.Xml.Serialization;
namespace SerializeRawXML
{
// [Serializable]
public class Insect
{
public string name;
// [NonSerialized]
[XmlIgnore] public int id;
public Insect(string name, int id)
{
this.name = name;
this.id = id;
}
public override string ToString()
{
return String.Format("{0}: {1}", name, id);
}
public Insect() {}
}
class SerializeRawXMLApp
{
[STAThread]
static void Main(string[] args)
{
Insect i = new Insect("Meadow Brown", 12);
XmlSerializer x = new XmlSerializer(typeof(Insect));
Stream s = File.Create("AnInsect.xml");
x.Serialize(s,i);
s.Seek(0, SeekOrigin.Begin);
Insect j = (Insect)x.Deserialize(s);
s.Close();
Console.WriteLine(j);
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?