HOW TO SAVE AN OBJECT TO A FILE WITH C#
C#
3
Posts
3
Posters
0
Views
1
Watching
-
I have a student class with attributes: name, id,... And I want to save it to a file then restore it. I don't know how to do that. Please help me.Thanks
Take a look at Serialization[^]
-
I have a student class with attributes: name, id,... And I want to save it to a file then restore it. I don't know how to do that. Please help me.Thanks
First you need to mark your class with the [Serializable] attribute so the fields/properties can be mapped to your output file. To write the file youve got a few options. First, you can use an XmlSerializer and TextWriter to write the file as XML formatted text. You can write the file as as Binary file using the FileStream and BinaryFormatter classes.