02-26-2010, 06:58 PM
bam Wrote:I like everyone else's weekend better than mine. Anyone want to trade?
Actually, I do. Can you debug this shit? I can't create the roster object, and then deserialize to it without breaking the program.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Serialization;
using System.IO;
namespace TravelExpenseConsoleApplication
{
class ExpenseRecorder
{
[STAThread]
static void Main(string[] args)
{
// Create list that holds roster object
ExpenseItemRoster roster = new ExpenseItemRoster();
/*
//Deserialize expenses
List<ExpenseItem> roster = null;
//List<ExpenseItem> roster = new List<ExpenseItem>();
try
{
BinaryFormatter formatter = new BinaryFormatter();
FileStream stream = new FileStream("c:\\myExpenses.bin", FileMode.Open, FileAccess.Read, FileShare.Read);
roster = (List<ExpenseItemRoster>)formatter.Deserialize(stream);
stream.Close();
}
catch (Exception ex)
{
Console.WriteLine("Unable to deserialize expense items: {0}", ex.Message);
}
//for this assignment we don't need to write the below line.
foreach (var e in roster) Console.WriteLine("Deserialized Expense Items {0}", e.ToString());
*/
Son, I am Disappoint.

