In general, software development consists of at least two parts of code and data, and the data is typically stored in a database such as SQL Server, Oracel, My sql, or in Excel, while serializable can serialize the object to the hard disk. Although it can only be applied to software development of lightweight data, it is really out of the box of DB, at least without installing SQL Server on the machine, and then executing a batch of SQL Script to create tables, stored procedures, and so on.
The code is simple enough to add a label for the attribute [Serializable] on the object that needs to be serialized
1 [Serializable]2 Public class DBObject 3 {4public list<dataobject> dataitems; 5 Public int Id; 6 Public string Name; 7 }
Store the code, where the file name can be arbitrarily taken, for example "Mydbfile.bin" can also:
DBObject dbobj=new dbobject ();
Dbobj= .....
New BinaryFormatter (); New FileStream ("Mydbfile.db", FileMode.Create, FileAccess.Write, fileshare.none); Formatter. Serialize (stream, dbobj); Stream. Close ();
Read the code, get dbobj, you want to use all the line, hehe:):
DBObject dbobj=new dbobject ();
New BinaryFormatter (); New FileStream ("Mydbfile.db, FileMode.Open, FileAccess.Read, fileshare.read); = (dbobject) formatter. Deserialize (stream); Stream. Close ();
Serializable, out of the bind to the DB