Sample:
代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace ChangedIndicator
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
System.Xml.Serialization.XmlSerializer xs
= new System.Xml.Serialization.XmlSerializer(typeof(MyCls));
MyCls obj = new MyCls { Id = 1, Name = "Rock Niu" };
using (MemoryStream mStream = new MemoryStream())
{
TextWriter tw = new StreamWriter(mStream, Encoding.UTF8);
xs.Serialize(tw, obj);
richTextBox1.Text = Encoding.UTF8.GetString(mStream.ToArray());
}
}
}
public class MyCls
{
public int Id { get; set; }
public string Name { get; set; }
}
}