Serializable, out of the bind to the DB

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.