How can I store (save) a variable, so that i can use it after I close and run the program again? I can’t use saveFileDialog cause it is 2D array. Other programs have their own extension. Can I make my own extension, too? Something like “Save project as…”.
Share
If you want to save some object to the disk, you either need to devise some file format for your data, or use one of the existing, generic ones.
In .Net, probably the simplest way is to use the binary formatter to do this:
The
objobject and all objects it references have to be serializable. Most primitive types already are serializable and you can make your own types serializable by using the[Serializable]attribute.The
Load()method would be similar, except it would useFile.OpenRead()andformatter.Deserialize().How to choose the file name is up to you, but you certainly can use
SaveFileDialogfor that.