右上,我有一个“EIR”类,即“Expense Report”这一基类清单:
using System;
using System.Collections.Generic;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Serialization;
using System.IO;
using System.Linq;
using System.Text;
namespace Payroll
{
[Serializable]
public class EIR : List<ExpenseItem>
{
public void WriteToFile(string filename)
{
try
{
BinaryFormatter formatter = new BinaryFormatter();
FileStream stream = new FileStream("D:\myExpensesUpdated.bin", FileMode.Create, FileAccess.Write, FileShare.None);
formatter.Serialize(stream, filename);
stream.Close();
}
catch (Exception ex)
{
Console.WriteLine("Unable to serialize Expenses: {0}", ex.Message);
}
}
public static EIR ReadFromFile(string filename)
{
EIR iRost = new EIR();
try
{
BinaryFormatter formatter = new BinaryFormatter();
FileStream stream = new FileStream("D:\myExpensesUpdated.bin", FileMode.Open, FileAccess.Read, FileShare.Read);
iRost = (EIR)formatter.Deserialize(stream);
}
catch (Exception ex)
{
Console.WriteLine("Unable to deserialize Expenses: {0}", ex.Message);
}
return iRost;
}
}
}
}
阅读法语区是个问题:
在主要方案中,这一部分试图称作“ReodFromFile”,并显示新更新的项目,但我发现的错误是“无法投放系统的物体”。 努力打造工资类型。
try
{
EIR expensesUpdated = EIR.ReadFromFile("D:\myExpensesUpdated.bin");
foreach (var e in expensesUpdated) Console.WriteLine("Updated: {0}", e.ToString());
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
我如何让“iRost”投薪。 EIR是哪类? 是否有某种办法将序列式插座转换成一个类别?