国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
將數(shù)據(jù)結構類型序列化和反序列化(BinaryFormatter類)
簡單例子如下:
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;

加上命名空間

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        //the struct to serializer
        [Serializable]
        public struct mydata
        {
            public string myname;
            public string mybirthday;
            public int age;
            public byte[] imageByte;
        }
//選擇保存路徑
        private void button1_Click(object sender, EventArgs e)
        {
            saveFileDialog1.Filter = "XML文件|*.xml";
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                textBox1.Text=saveFileDialog1.FileName;
        }
//將數(shù)據(jù)結構序列化到bat或其他格式文件中
        private void button2_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "")
                return;
            mydata newdata = new mydata();
            newdata.myname = "龍域";
            newdata.mybirthday = "09-31";
            newdata.age = 23;
            newdata.imageByte = Encoding.Default.GetBytes("999adfklasdjfl".ToCharArray());
            IFormatter formatter = new BinaryFormatter();
            FileStream fs = new FileStream(textBox1.Text, FileMode.OpenOrCreate);
            formatter.Serialize(fs, newdata);
            fs.Close();
        }
//反序列化二進制文件
        private void button3_Click(object sender, EventArgs e)
        {
            IFormatter formter = new BinaryFormatter();
            FileStream fs = new FileStream(textBox1.Text,FileMode.Open);
            mydata mm=(mydata)formter.Deserialize(fs);
            MessageBox.Show("mm.Name="+mm.myname+"\r\n"+
                             "mm.bothday=" + mm.mybirthday + "\r\n" +
                             "mm.age="+mm.age+"\r\n"+
                             "mm.imageByte="+Encoding.Default.GetString(mm.imageByte));
            fs.Close();
        }
    }
本站僅提供存儲服務,所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權內(nèi)容,請點擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
快速掌握VB.NET讀寫文本文件操作
C# 二進制BinaryFormatter進行序列化與反序列化
ASP.NET中序列化與反序列化-以顯示上一次登錄的信息為例
關于BinaryFormatter
C#序列化和反序列化 (BinaryFormatter、SoapFormatter、XML序列化)
C# DataSet對象序列化并壓縮和反序列化及解壓縮
更多類似文章 >>
生活服務
分享 收藏 導長圖 關注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服