[英]How can I search a record from a Txt file with large amount record in WP7?
I had 10000+ unicode record in my txt file, i using this function for search record from the Txt File: 我的txt文件中有10000+条unicode记录,我使用此功能从Txt文件中搜索记录:
Dictionary<string, string> myLookupTable = new Dictionary<string, string>();
private void LoadFile(){
var resource = Application.GetResourceStream(new Uri("datatxt.txt", UriKind.Relative));
StreamReader streamReader = new StreamReader(resource.Stream,System.Text.Encoding.Unicode);
string line;
char[] spaceSeparator = new char[] { ','
string[] result;
while (!streamReader.EndOfStream)
{
line = streamReader.ReadLine();
result = line.Split(spaceSeparator, StringSplitOptions.None);
myLookupTable.Add(result[0],result[1]);
}
}
It said "Value does not fall within the expected range." 它说:“价值不在预期范围内。” from "myLookupTable.Add(result[0],result[1]);" 来自“ myLookupTable.Add(结果[0],结果[1]);”
Anyone know what is the reason of this error and how can i solve it? 谁知道此错误的原因是什么,我该如何解决?
Thanks a lot!! 非常感谢!!
Instead of using 而不是使用
myLookupTable.Add(result[0],result[1]);
you may use 你可以用
if(!myLookupTable.ContainsKey(result[0]))
{
myLookupTable.Add(result[0],result[1]);
}
else
{
//You have to implement this based on your application business rules
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.