Click here to Skip to main content
16,023,224 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
• Each CSub object must now be added to the ArrayList (supplied as a method parameter), and not to listbox lstSub
• After all the records were loaded, the method must return 0

IFormatter serializer;
FileStream subFile;
CSub newSub;
try
{
    if (File.Exists("Submarines.bin"))
    {
        lstSub.Items.Clear();
        serializer = new BinaryFormatter();
        subFile = new FileStream("Submarines.bin", FileMode.Open, FileAccess.Read);

        long fileLength = subFile.Length;
        while (subFile.Position < fileLength)
        {
            newSub = new CSub();
            newSub = serializer.Deserialize(subFile) as CSub;
            lstSub.Items.Add(newSub);
        }
        subFile.Close();
        UC.MB("Submarines Loaded", lstSub.Items.Count + " submarine records were successfully loaded from the file Submarines.bin");
    }
    else
    {
        UC.MB("File not found", "Could not find the file Submarines.bin");
    }
}
catch (Exception ex)
{
    UC.MB("mnuiLoadSub_Click", ex.Message);
}
finally
{
    serializer = null;
    subFile = null;
    newSub = null;
}
Posted
Updated 16-Aug-10 3:06am
v2
Comments
Prasad Bansi Vagal 16-Aug-10 9:08am    
Reason for my vote of 5
nice quest

1 solution

:-D Please mention your question clearly as why should it return 0 and for what the code is? please quote the question again and clearly explain the problem.
Prasad
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900