개체 배열과 문자열을 직렬화하려고합니다.다른 유형의 여러 객체를 직렬화하는 방법은 무엇입니까?
FileStream s;
s = new FileStream(openfile.FileName, FileMode.Open, FileAccess.Read);
BinaryFormatter bf = new BinaryFormatter();
string password = (string)bf.Deserialize(s);
ch.chaps = (Chapter[])bf.Deserialize(s);
s.Close();
int i;
if (password == txtPassword.Text)
{
for (i = 0; i <= 1000; i++)
{
try
{
combChapSelect.Items.Add(ch.chaps[i].chapName);
}
catch
{
i = 1000;
}
}
}
이 코드와 비주얼 스튜디오는이 오류가 없다하지만 파일을 선택하면 OpenFileDialog를이 닫히지 않습니다 말한다 :
FileStream s;
s = new FileStream(savefile.FileName, FileMode.Create, FileAccess.Write);
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(s, ch.chaps);
bf.Serialize(s, txtPassword.Text);
s.Close();
이 역 직렬화 코드는 다음과 같습니다이 직렬화 코드 아무 일도 일어나지 않습니다. 내가 잘못한 것을했거나 다른 객체 유형을 직렬화하는 다른 방법이 있습니까?
챕터가 ISerializable을 구현합니까? "직렬화"하려고하지만 코드에서 "비 직렬화"를 호출한다고 가정합니다. 그래서 당신은 serialize하거나 deserialize하려고합니까? –