zoukankan      html  css  js  c++  java
  • 序列化范例

    using UnityEngine;
    using System.Collections;
    using System;
    
    [Serializable]
    public class test
    {
        public int n1 = 0;
        public int n2 = 5;
        // [NonSerialized]
        public string str = null;
    }
    using UnityEngine;
    using System.Collections;
    using System.Runtime.Serialization;
    using System.Runtime.Serialization.Formatters.Binary;
    using System.IO;
    
    public class get : MonoBehaviour {
    
        // Use this for initialization
        void Start () {
            test obj = new test();
            obj.n1 = 1;
            obj.n2 = 2;
            obj.str = "简单的字符串";
            
            IFormatter formater = new BinaryFormatter();
            Stream stream = new FileStream("c:/SaveDtat.bin", FileMode.Create, FileAccess.Write, FileShare.None);
            formater.Serialize(stream, obj);
            stream.Close();
            
            
            IFormatter formatter = new BinaryFormatter();
            Stream reader_stream = new FileStream("c:/SaveDtat.bin", FileMode.Open, FileAccess.Read, FileShare.Read);
            test readerObj = (test)formatter.Deserialize(reader_stream);
            reader_stream.Close();
            
            Debug.Log(readerObj.n1);
            Debug.Log(readerObj.n2);
            Debug.Log(readerObj.str);
        }
        
        // Update is called once per frame
        void Update () {
        
        }
    }
  • 相关阅读:
    2-4 递增链表的插入 链表
    KMPnext数组自看
    Shortest Prefixes POJ
    Xor Sum HDU
    Immediate Decodability HDU
    Repository HDU
    "strcmp()" Anyone? UVA
    Remember the Word UVALive
    A Magic Lamp HDU
    Check Corners HDU
  • 原文地址:https://www.cnblogs.com/softimagewht/p/3885579.html
Copyright © 2011-2022 走看看