• 序列化和反序列化


    /*              #########                       
                  ############                     
                  #############                    
                 ##  ###########                   
                ###  ###### #####                  
                ### #######   ####                 
               ###  ########## ####                
              ####  ########### ####               
             ####   ###########  #####             
            #####   ### ########   #####           
           #####   ###   ########   ######         
          ######   ###  ###########   ######       
         ######   #### ##############  ######      
        #######  #####################  ######     
        #######  ######################  ######    
       #######  ###### #################  ######   
       #######  ###### ###### #########   ######   
       #######    ##  ######   ######     ######   
       #######        ######    #####     #####    
        ######        #####     #####     ####     
         #####        ####      #####     ###      
          #####       ###        ###      #        
            ###       ###        ###              
             ##       ###        ###               
    __________#_______####_______####______________
        身是菩提树,心如明镜台,时时勤拂拭,勿使惹尘埃。
                    我们的未来没有BUG              
    * ==============================================================================
    * Filename: Text11
    * Created:  $time$
    * Author:   WYC
    * Purpose:  序列化和反序列化
    * ==============================================================================
    */
    using System;
    using System.IO;
    using System.Runtime.Serialization.Formatters.Binary;
    using UnityEngine;
    
    public class Text11 : MonoBehaviour {
    
        
        void Start () {
            //BinaryFormatterWrite();
            //BinaryFormatterRead();
        }
        public void BinaryFormatterRead()
        {
            PerSonqwer p = new PerSonqwer();
            using (FileStream fsRead = new FileStream(@"C:UsersAdministrator.PC-201709211725Desktop王1.txt", FileMode.OpenOrCreate, FileAccess.Read))
            {
                //开始反序列化
                BinaryFormatter bf = new BinaryFormatter();
                p = (PerSonqwer) bf.Deserialize(fsRead);
            }
            print("反序列化");
            print(p.Name);
            print(p.Age);
            print(p.Gender);
        }
    
    
        public void BinaryFormatterWrite() {
            PerSonqwer p1 = new PerSonqwer();
            p1.Name = "张三";
            p1.Age = 21;
            p1.Gender = "";
            using (FileStream fsWrite = new FileStream(@"C:UsersAdministrator.PC-201709211725Desktop王1.txt", FileMode.OpenOrCreate, FileAccess.Write))
            {
                //开始序列化
                BinaryFormatter bf = new BinaryFormatter();
                bf.Serialize(fsWrite, p1);
                print("序列化");
            }
        }
    
    
        void Update () {
            
        }
    }
    [Serializable]
    public class PerSonqwer
    {
        public string Name;
        public int Age;
        public string Gender;
    }
  • 相关阅读:
    Google Style Guides-Shell Style Guide
    支付宝钱包手势password破解实战(root过的手机可直接绕过手势password)
    学习Java JDBC,看这篇就够了
    php学习之道:WSDL具体解释(一)
    Android学习笔记(17):文本框TextView类
    HttpSession的深入分析与研究
    【leetcode】atoi (hard) ★
    【leetcode】Candy(hard) 自己做出来了 但别人的更好
    【leetcode】Substring with Concatenation of All Words (hard) ★
    【leetcode】 Search a 2D Matrix (easy)
  • 原文地址:https://www.cnblogs.com/mclll520/p/8110711.html
Copyright © 2020-2023  润新知