我有一个Lat/Lon坐标列表,我在while(true)循环中处理。在循环过程中,我构建了一个查询,该查询将被发送到远程服务进行处理。远程服务只能接受12对Lat/Lon坐标,但是我的列表可能包含数千个坐标。我想要做的是构建查询,然后发送它每12个循环处理。如何解决这个C#循环和处理代码?
List<string[]> lList = FromDB();
int i = 0;
int intLastIndex - lList.Count;
string strQuery = String.Empty
while(true)
{
strQuery = lList[i][0] + "|" + lList[i][1];
if(((i % 11) == 0) && (i != 0))
{
SendToRemoteService(strQuery);
strQuery = String.Empty;
}
if(i == intLastIndex)
{
break;
}
i++
}
但是,这会生成一个数组越界的异常,并且不会处理所有记录。任何人都可以提出更好的方法?
马克
每当我觉得我的权利,我看到另一个bug – 2010-01-17 02:28:42
我们应该使用TDD这个=) – 2010-01-17 02:29:21
通过使用GroupBy语句,你将有所有的数据在内存中(照顾你的内存;)) – Maghis 2010-01-17 02:33:21