What is this 'Serializable' why do we need it and how do we use it? Any
link or simple example would be great.
Serialization is the act of being able to take an instance of an object
and save it in its current state to another storage medium. In .NET, this
is always a stream, but since streams can have different backings, the uses
for this mechanism are virtually limitless.
One use is in remoting situations. When you pass parameters to/from a
method that is being executed in an app domain outside of your own,
serialization is used to package the parameters into byte streams that can
be passed to the other app domain.
You can also save the stream to a file on disk, or in a database, and
then deserialize the instance later, continuing to use it.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com
"DBC User" <dbc...@gmail.com> wrote in message
news:1146512022....@g10g2000cwb.googlegroups.com...
Cheers,
Greg
"DBC User" <dbc...@gmail.com> wrote in message
news:1146512022....@g10g2000cwb.googlegroups.com...
See inline:
> Serialization just means to store an object as a byte stream. It will
> typically be an XML text byte stream, or a binary byte stream.
A byte stream is a byte stream, there isn't a different flavor to either
of them. How they are interpreted is a different thing. The SOAP formatter
serializes instances into SOAP messages, which ultimately can be stored as a
byte stream, while the binary formatter uses a much more compact
representation.
> You need this functionality to store an object in a file, or to send it
> over a
> wire. An object that is "serializable" meets the criteria for being
> serialized automatically into XML (typically meaning it has public
> read/write properties, at least one empty constructor overload, and
> perhaps a few others).
It is eligible to be serialized using the SOAP formatter (which produces
XML), but it does not automatically mean that you can use XML serialization.
> In order to be serialized as XML you will lose the methods, of course.
> XML serialization is typically used for data container classes and
> collections.
> Binary serialization can preserve
> the methods and private members, but people normally don't speak in
> terms of binary serialization.
This isn't true. When you serialize an instance of a type, the method
information is not stored. That is a part of the type itself, and there is
no reason to store it. Rather, just the field values are stored. Storing
the method information would mean you are storing code in some way, or local
variables, and that's not what happens. It would make no sense to do so.