文件序列化正常,返序列化出错
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; }
}
}
}
已经引用命名空间了为什么会提示同错的呢