Example show how the serialize the individual objects using a Binary Formatter.
I have commented the code very well. please let me know in case of any doubts.
Thanks
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Creating rectangle type object
Dim R1 As New Rectangle
'initializing the X object
R1.X = 1
'initializing the Y object
R1.Y = 1
'initializing the width object
R1.Width = 10
'initializing the height object
R1.Width = 20
'Creating rectangle type object
Dim R2 As New Rectangle
'initializing the X object
R2.X = 10
'initializing the Y object
R2.Y = 10
'initializing the width object
R2.Width = 100
'initializing the X object
R2.Height = 200
'creating the filestream
Dim savefile As FileStream
'create the file and return reference
savefile = File.Create(Directory.GetCurrentDirectory & "\Shapes.bin")
'creating Binary formatter
Dim formatter As System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
'intializing binary formatter
formatter = New System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
'serializing the rectangle objects to the file
formatter.Serialize(savefile, R1)
formatter.Serialize(savefile, R2)
'closing the file
savefile.Close()
MsgBox("Individual objects serialized successfully")
End Sub