zoukankan      html  css  js  c++  java
  • BinaryFormatter.cs

    /*
     * C# Programmers Pocket Consultant
     * Author: Gregory S. MacBeth
     * Email: gmacbeth@comporium.net
     * Create Date: June 27, 2003
     * Last Modified Date:
     * Version: 1
     */
    using System;
    using System.IO;
    using System.Runtime.Serialization.Formatters.Binary;

    namespace Client.Chapter_11___File_and_Streams
    {
        class Class1
        {
            [STAThread]
            static void Main(string[] args)
            {
                Point p1 = new Point();

                p1.xpoint = 0x1111;
                p1.ypoint = 0x2222;

                // Opens a file and serializes the object into it.
                Stream stream = File.Open("onepoint.bin", FileMode.Create);
                BinaryFormatter bformatter = new BinaryFormatter();

                bformatter.Serialize(stream, p1);
                stream.Close();

                //Read the data from a file and desiralize it
                Stream openStream = File.Open("onepoint.bin", FileMode.Open);
                Point desierializedPoint = new Point();

                desierializedPoint = (Point)bformatter.Deserialize(openStream);
            }
        }
        [Serializable()]
        class Point
        {
            public int xpoint;
            public int ypoint;
        }

    }
  • 相关阅读:
    java基础——DecimalFormat
    剑指——重建二叉树
    error error: illegal character: 'u3000'
    Android: Unhandled exception java.net.malformedurlexception 异常笔记
    Android获取系统时间
    java基础——hashCode笔记
    golang 红黑树
    golang 实现跳表skiplist
    快排
    堆排序
  • 原文地址:https://www.cnblogs.com/shihao/p/2501878.html
Copyright © 2011-2022 走看看