文件序列化正常,返序列化出错
using System;using System.Collections.Generic;
using System.IO;
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();
}
}
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; }
}
}
}
已经引用命名空间了为什么会提示同错的呢
你的文件是序列化过的吗 对这个文 件在桌面里
页:
[1]