/// <summary> /// 对加载的词典排序并重新写入 /// </summary> /// <param name="Reload">是否重新加载</param> public void SortDic(bool Reload) { DateTime start = DateTime.Now; StreamWriter sw = new StreamWriter(DicPath, false, System.Text.Encoding.UTF8); IDictionaryEnumerator idEnumerator1 = htWords.GetEnumerator(); while (idEnumerator1.MoveNext()) { IDictionaryEnumerator idEnumerator2 = ((Hashtable)idEnumerator1.Value).GetEnumerator(); while (idEnumerator2.MoveNext()) { SegList aa = (SegList)idEnumerator2.Value; aa.Sort(); for (int i = 0; i < aa.Count; i++) { if (aa.GetElem(i).ToString() == "null") { sw.WriteLine(idEnumerator1.Key.ToString() + idEnumerator2.Key.ToString()); } else { sw.WriteLine(idEnumerator1.Key.ToString() + idEnumerator2.Key.ToString() + aa.GetElem(i).ToString()); } } } } sw.Close(); if (Reload) { InitWordDics(); } TimeSpan duration = DateTime.Now - start; m_EventTime = duration.TotalMilliseconds; }