如何将对象转换为2维分支字符串数组

时间:2013-05-03 12:08:23

标签: c# arrays serialization type-conversion

我有一个2维分支数组。我将其转换为对象并通过序列化程序将其写入文件。 (转换为序列化程序的对象原因,你知道) 现在我读取这个文件并将对象恢复 - 但我如何能够将对象转换回2d分支数组?

提前致谢!

修改

// read object
SerializedObjectRead sr = new SerializedObjectRead();
sr.FileStreamName = @"E:\LOG\test.bin";
int intSuccesfullR = sr.Reader();
object back = new object();
if (intSuccesfullR == 0)
{
back = sr.ReadObj;
}

// here i want to convert the object to the 2d array


// my reader class
public class SerializedObjectRead
{
public string FileStreamName;
public object ReadObj;

public int Reader()
{
int intSuccesfull = 0;
try
{
IFormatter formatter = new BinaryFormatter();
Stream stream = new FileStream(FileStreamName, FileMode.Open, FileAccess.Read, FileShare.Read);
ReadObj = formatter.Deserialize(stream);
stream.Close();
}
catch
{
intSuccesfull = -1;
}

return intSuccesfull;
}
}

1 个答案:

答案 0 :(得分:1)

您可以将对象强制转换为所需类型。

object b;
example[,] r = (example[,])b;