I have a simple structure, as follows.
public struct Structure
{
public byte Style;
public string Value1;
public string Value2;
public int Value3;
public bool Active;
}
I’d like to store an array of this structure using variable size as a file. This file will be automatically loaded upon launch of the program, and updated as the program is in use. I can figure out how to use it within the program, I’m just unsure on the method I should be using to store it. I’m guessing I should use a binarywriter with prefixed byte lengths for each value? If that’s correct, an example of how to store and load a Structure[X] array would be incredibly helpful. For aesthetic reasons, I would like to keep it in a file with a custom extension(ie: Array.ext), though I am not opposed to any other solution that will keep the data stored in that format between launches.
You have a few options. If you need the file to be stored in human readable format you can use an XML or JSON Serializer/Deserializer. Here is an XML example
If you want to use a binary serializer
You need to mark your class as
[Serializable]as well