Object Oriented Programming using C#

(backadmin) #1

Object Oriented Programming using C#
Generic Collections and how to Serialize them


In order to do this no changes need to be made to the Account class or the Bank class though we must tell the compiler
these classes can be serialiazed.


To do this we place the keyword serializable in front of each class as shown below....


[Serializable]
class Account
{
// code from body of class omitted
}
[Serializable]
class Bank
{
// code from body of class omitted
}

In the ‘Main’ method that we will use to invoke the serialization \ de-serialization process, and to test the results, we need
to add additional using statements as we are using additional parts of the .NET framework (see below).


using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Serialization;
using System.IO;

A complete ‘Main’ method that will demonstrate this working is provided below. Much of this is either self explanatory
or contains code we are already familiar with. The new parts that relate to the serialiazation / de-serialization will be
explained afterwards.

Free download pdf