Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
c#加载/保存对象或对象数组_C#_Arrays_Object_Save_Load - Fatal编程技术网

c#加载/保存对象或对象数组

c#加载/保存对象或对象数组,c#,arrays,object,save,load,C#,Arrays,Object,Save,Load,我想这是我使用的代码,但是如果不能够加载它,就无法判断, 基本上,imagebook是一个存储“imagedata对象数组”的单个对象,其中包含用于我的加载保存的图像和整数。 但在load sub中的一条线路上存在“type”错误问题 如果有办法保存整个imagedata数组并删除imagebook,也可以 namespace FastCrack { [Serializable] class ImageBook1 { public ImageData1[]

我想这是我使用的代码,但是如果不能够加载它,就无法判断, 基本上,imagebook是一个存储“imagedata对象数组”的单个对象,其中包含用于我的加载保存的图像和整数。 但在load sub中的一条线路上存在“type”错误问题

如果有办法保存整个imagedata数组并删除imagebook,也可以

namespace FastCrack
{
    [Serializable]
    class ImageBook1
    {
        public ImageData1[] imgdat;
        public ImageBook1(ImageData1[] dat) {
            imgdat = new ImageData1[1000];
            imgdat = dat;
        }
    }
}




namespace FastCrack
{
    public partial class Form1 : Form
    {
        private void saveCrack()
        {      
        try
        {
              book1 = new ImageBook1(imagedataSheets);
            // Create a FileStream that will write data to file.
            FileStream writerFileStream = new FileStream(Filename1, FileMode.Create, FileAccess.Write); // Save our dictionary of friends to file
            this.formatter.Serialize(writerFileStream, this.book1); 
            writerFileStream.Close();
        }
        catch (Exception) {
            Console.WriteLine("Unable to save our friends' information");
        } // end try-catch
        }


        private void loadCrack()
        {

            if (File.Exists(Filename1))
            {

                try
                {
                    // Create a FileStream will gain read access to the 
                    // data file.
                    FileStream readerFileStream = new FileStream(Filename1,
                        FileMode.Open, FileAccess.Read);
                    // Reconstruct information of our friends from file.




  //this.friendsDictionary = (Dictionary<String, Friend> 
 //<--this is line from example

this.book1 = (Dictionary<ImageBook1, book1>) 
 // (Dictionary<String, Friend>)
    <--  this is the line giving me type error




                        this.formatter.Deserialize(readerFileStream);
                    // Close the readerFileStream when we are done
                    readerFileStream.Close();

                }
                catch (Exception)
                {
                    Console.WriteLine("There seems to be a file that contains " +
                        "friends information but somehow there is a problem " +
                        "with reading it.");
                } // end try-catch

            } // end if
        }
    }
}
namespace快速破解
{
[可序列化]
第1册
{
公共图像数据1[]imgdat;
公共ImageBook1(ImageData1[]dat){
imgdat=新图像数据1[1000];
imgdat=dat;
}
}
}
名称空间快速破解
{
公共部分类Form1:Form
{
私有void saveCrack()
{      
尝试
{
book1=新的ImageBook1(图像数据表);
//创建一个将数据写入文件的文件流。
FileStream writerFileStream=new FileStream(Filename1,FileMode.Create,FileAccess.Write);//将我们的朋友字典保存到文件
this.formatter.Serialize(writerFileStream,this.book1);
writerFileStream.Close();
}
捕获(例外){
Console.WriteLine(“无法保存我们朋友的信息”);
}//结束尝试捕捉
}
私有void loadCrack()
{
if(File.Exists(Filename1))
{
尝试
{
//创建文件流将获得对
//数据文件。
FileStream readerFileStream=新的FileStream(Filename1,
FileMode.Open,FileAccess.Read);
//从文件中重建我们朋友的信息。
//this.friendsDictionary=(字典

//
book1
变量似乎是一个
ImageBook1
(不确定;您没有与我们共享其声明),因此无法为其分配字典

序列化的任何类型也应该是反序列化的类型,因此您可能希望将其转换回
ImageBook1

this.book1 = (ImageBook1)this.formatter.Deserialize(readerFileStream);

如果没有,您将不得不编辑您的答案并指出您想要哪种类型的词典。

“但是在加载子部分的某一行出现“type”错误的问题。”--是否愿意共享哪一行?this.book1=(dictionary)您将看到最后的箭头非常有效谢谢!!我也很高兴,因为我从未使用过词典b4!!