Пример сохранения в файл и чтения из файла данных, упакованных в структуру. Предварительно в дизайнере на форму были добавлены элементы управления: numericUpDown1, textBox1, butLoad и butSave. using System;
using System.Text;
using System.Windows.Forms;
namespace Test
{
public partial class Form1 : Form
{
// Структура для сохранения / загрузки
[Serializable]
private struct _test_structure
{
public Int32 a;
public String s;
}
private _test_structure test_structure;
public Form1()
{
InitializeComponent();
}
// Сохранение структуры в файл
private void butSave_Click(object sender, EventArgs e)
{
System.IO.FileStream fstream = new System.IO.FileStream("test.bin", System.IO.FileMode.Create);
test_structure.a = (int)numericUpDown1.Value;
test_structure.s = textBox1.Text;
System.Runtime.Serializatio