別の質問を見て、hereに質問してみてください。辞書をバイナリファイルに保存する
だから私はここに辞書を持っている:
private static Dictionary<int, string> employees = new Dictionary<int, string>();
//the int key is for the id code, the string is for the name
は辞書が名前を持つ従業員で満たされていると仮定し、識別コード
をので、私は、バイナリファイルを使用して「それを保存する」にこれを試してみました:
FileStream binaryfile = new FileStream(@"..\..\data\employees.bin", FileMode.OpenOrCreate);
var binaryFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
binaryFormatter.Serialize(@"..\..\data\employees.bin", employees);
binaryfile.Close();
しかし、この手法はオブジェクトに対してのみ機能するようです。ここ
は私が取得エラーです:
The best overloaded method match for 'System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(System.IO.Stream, object)' has some invalid arguments
私の目標は、単にバイナリファイルを読み込むことで保存された辞書を取得することです。 (それが可能な場合でも)
あなたは 'binayFormatter.Serialize'のあなたの引数の1つが間違っていると考えましたか? – yaakov