标题:文件序列化正常,返序列化出错
只看楼主
jaki009
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2009-5-15
结帖率:0
 问题点数:0 回复次数:0 
文件序列化正常,返序列化出错
using System;
using System.Collections.Generic;
using
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
namespace 返序列化
{
    class Program
    {
        static void Main(string[] args)
        {
            Person p;
            //p.Name = "张三";
            //p.Age = 30;
            //p.Gender = '男';
            using (FileStream fsread = new FileStream(@"C:\Users\Administrator\Desktop\cc.txt", FileMode.OpenOrCreate, FileAccess.Read))
            {
                //开始序列化对象
                BinaryFormatter bf = new BinaryFormatter();
                p = (Person)bf.Deserialize(fsread);
            }
            Console.WriteLine(p.Name);
            Console.WriteLine(p.Age);
            Console.WriteLine(p.Gender);
            Console.ReadKey();
        }
    }
    [Serializable]
    public class Person
    {
        private string _name;
        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }
        private int _age;
        public int Age
        {
            get { return _age; }
            set { _age = value; }
        }
        private char _gender;
        public char Gender
        {
            get { return _gender; }
            set { _gender = value; }
        }
    }
}
已经引用命名空间了为什么会提示同错的呢
搜索更多相关主题的帖子: Desktop Users 
2014-11-29 08:33



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-439328-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.610870 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved