我正在尝试在C#中对字典进行序列化和反序列化。问题是,当我进行反序列化时,需要3-4分钟。文本文件的大小是4.3 MB这是我的代码..请帮帮我。
[Serializable]
public class WordTag
{
public String Word, Tag;
public double prob;
public WordTag()
{ }
public WordTag(String W, String T)
{
Word = W;
Tag = T;
}
[Serializable]
public class EqualityComparer : IEqualityComparer<WordTag>
{
public bool Equals(WordTag x, WordTag y)
{
return x.Word == y.Word && x.Tag == y.Tag;
}
public int GetHashCode(WordTag x)
{
return base.GetHashCode();
}
}
}
.....................
try
{
using (Stream stream = File.Open("e:\\WordTagFreq.txt", FileMode.Open))
{
BinaryFormatter bin = new BinaryFormatter();
WordTagDic.Clear();
WordTagDic = (Dictionary<WordTag, int>)bin.Deserialize(stream);
}
}
catch (IOException)
{
}
答案 0 :(得分:2)