阿牛 - 专注.NET开发

如果梦想与实现之间有一道不可逾越的鸿沟,那么“执行力”就是跨越这道鸿沟的桥梁。

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Sample:

untitled

代码:

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; }
    }
}

posted on 2009-06-24 16:27  阿牛-专注金融行业开发  阅读(270)  评论(0编辑  收藏  举报