确实序列化和反序列化列表< class>什么改变? [英] does serialize and deserialize the list<class> changes anything?

查看:83
本文介绍了确实序列化和反序列化列表< class>什么改变?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi
i有一个应用程序,我保存我的数据,保存到数据库,然后在需要时获取数据,比如保存和恢复

i有列表<> ;对象(类)并将它们序列化为二进制数据然后反序列化以进行恢复,我可以看到数据保存和恢复,但是当我运行我的程序时出现错误,我真的不明白它来自哪里,如果我运行我的应用程序没有保存和恢复,它将运行没有错误但在恢复相同的数据后,程序将中断错误,我的类的详细信息和错误解释如下。



上课我认为与错误相关:



Hi i have an application in which i save my data, save it to the database and then fetch the data whenever i need it, something like save and restore
i have list<> of objects (class) and serialize them to binary data then deserialize it for restoring,i can see that the data saved and restored as well, but when i run my program there is an error that i really don`t understand where it came from , if i run my application without save and restore , it will run without error but after restoring the same data the program will interrupt with an error, the details of my class and the error are explained below.

class i think related to the error :

[Serializable]
   class prof:faculty
   {

       public prof(string n, int ID, string f, string d, int did) : base(f,d,did)
        { nprof++; id = ID; name = n; }

       public prof(string n, int ID,faculty f, department d)
           : base(f,d)
       {
           nprof++; id = ID; name = n;
       }

       public prof(prof p, faculty f, department d)
           : base(f,d)
       {id=p.FId; name = p.FName; }


       public int PId { get { return id; } set { id = value; } }
       public string PName { get { return name; } set { name = value; } }
       public static int Nprof { get { return nprof; } }
       public void addcourse(course c) { teaching.Add(c); }
       public List<course> Teaching { get { return teaching; } }

       public void addtime(int d, int[] s) { teachingprog.Add(d,s); }
       public Dictionary<int, int[]> Teachingprog { get { return teachingprog; } }



       private string name;
       private int id;
       public Dictionary<int, int[]> teachingprog = new Dictionary<int, int[]>();
       private List<course> teaching = new List<course>();


       static int nprof = 0;
   }







错误:








error:


foreach (course cc in p.Teaching)
                           for (int j = 0; j < Nroom; j++)
                           {
                               int ii = Courses.IndexOf(cc);







这是错误部分,int ii的值为-1(使其下面的计算错误)如果我没有错,则意味着cc无法在课程列表中找到<>



但为什么?

i序列化教学列表<>和课程<> list

保存和恢复前没有错误,但是恢复后出现错误




this is the error part, int ii valued with -1(makes its following computation wrong) which if i am not wrong means cc could not be found in courses list<>

but why?
i serialize the prof list<> and the courses<> list
no error before save and restore, but after restore there is a error

推荐答案

请阅读我对该问题的评论。这使得直接答案是不可能的。



我建议阅读这些:

序列化(C#和VB) [ ^ ]

XML序列化和反序列化:第1部分 [ ^ ]

XML序列化和反序列化:第2部分 [ ^ ]
Please, read my comment to the question. That makes that direct answer is impossible.

I'd suggest to read these:
Serialization (C# and VB)[^]
XML Serialization and Deserialization: Part-1[^]
XML Serialization and Deserialization: Part-2[^]


这篇关于确实序列化和反序列化列表&lt; class&gt;什么改变?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆