Good day!

In windos form through textboxes, data is entered and edited for 4x multi-dimensional arrays.

Upon completion of the work, it is necessary that all elements of the arrays retain their current value, and when you start the program again, load the latest data.

I looked for a solution, I saw serialization. I tried binary serialization. Not much happened.

Код: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; using System.Runtime.Serialization.Formatters.Binary; using System.Runtime.Serialization; namespace CityStatic { [Serializable] class Mass { public uint[,,,,,] massive { get; set; } public uint[,,,,,] massive1 { get; set; } public uint[,,,,,] massive2 { get; set; } public uint[,,,,,] massive3 { get; set; } public Mass(uint[,,,,,] massive, uint[,,,,,] massive1, uint[,,,,,] massive2, uint[,,,,,] massive3, uint[,,,,,]) { //??? } } public partial class Form1 : Form { public Form1() { InitializeComponent(); } //Π‘ΠΎΠ·Π΄Π°Π½ΠΈΠ΅ массива //-------------------- Mass[,,,,,] massive = new Mass[10, 10, 10, 10, 11, 11]; Mass[,,,,,] massive1 = new Mass[10, 10, 10, 10, 11, 11]; Mass[,,,,,] massive2 = new Mass[10, 10, 10, 10, 11, 11]; Mass[,,,,,] massive3 = new Mass[10, 10, 10, 10, 11, 11]; /* здСсь ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ° ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»ΡŒΡΠΊΠΎΠ³ΠΎ записи Π΄Π°Π½Π½Ρ‹Ρ… Π² массивы ΠΏΡƒΡ‚Π΅ΠΌ Π²Π²ΠΎΠ΄Π° Π² тСкстбоксы, ΠΏΡ€ΠΈ Π½Π°ΠΆΠ°Ρ‚ΠΈΠΈ Π½Π° ΠΎΠ΄Π½Ρƒ ΠΈΠ· 4Ρ… ΠΊΠ½ΠΎΠΏΠΎΠΊ относит запись Π² ΠΎΠ΄ΠΈΠ½ ΠΈΠ· 4Ρ… массивов */ BinaryFormatter formatter = new BinaryFormatter(); using (FileStream fs = new FileStream("mass.dat", FileMode.OpenOrCreate)) // здСсь всС красноС { formatter.Serialize(fs, massive); // здСсь Ρ‚ΠΎΠΆΠ΅ } 

}

  • one
    So the question is what? - Alexander Petrov
  • one
    Namespace opened? using System.IO; It is in the file where you are doing the serialization. Or do you have everything in a heap in one file? - Alexander Petrov
  • The question is how to save the data of several multidimensional arrays? I have everything in a heap in one file, a small program was planned, but over time it grew like a snowball - user292188
  • Put your arrays in another array. The serializer will eat and spit out the file for you. You will also serialize back, do not forget that you have an array of arrays. - adrug

1 answer 1

Simple and versatile way to serialize. Can serialize everything at all. Although the array of arrays, which store 10 more nested arrays :)

When this catches IO errors. Use this:

 List<Cookie> asdf = new List<Cookie>(); //сСриализация Serializer.Save("data.bin", asdf); //дСсСриализация asdf = Serializer.Load<List<Cookie>>("data.bin"); 

Class Code:

 public static class Serializer { public static void Save(string filePath, object objToSerialize) { try { using (Stream stream = File.Open(filePath, FileMode.Create)) { BinaryFormatter bin = new BinaryFormatter(); bin.Serialize(stream, objToSerialize); } } catch (IOException) { } } public static T Load<T>(string filePath) where T : new() { T rez = new T(); try { using (Stream stream = File.Open(filePath, FileMode.Open)) { BinaryFormatter bin = new BinaryFormatter(); rez = (T) bin.Deserialize(stream); } } catch (IOException) { } return rez; } }