C# 4.0 如何在c#中解析此循环?
我使用visual studio 2010在一个c#桌面应用程序中工作。 我想阅读每一条记录,并为每个美国州加载一本“街道名称词典”。 例如,我读取第一条记录(id=1),因此我加载AlabamaDictionary.txt,因为该记录来自阿拉巴马州,加载后,启动另一个进程,如地址标准化等。当该进程完成时,我读取下一条记录(id=2),我必须检查“状态”是否相同,是否与之前的状态相同,我不需要再次加载AlabamaDictionary.txt,因为它还没有加载,请启动另一个进程,如地址标准化。当这个过程结束时,我读取下一条记录(id=3),它来自“亚利桑那州”。这里的状态发生了变化,所以我需要加载Arizona.txt并再次启动另一个地址标准化过程,等等。。。 我的问题是换字典,什么时候换字典C# 4.0 如何在c#中解析此循环?,c#-4.0,C# 4.0,我使用visual studio 2010在一个c#桌面应用程序中工作。 我想阅读每一条记录,并为每个美国州加载一本“街道名称词典”。 例如,我读取第一条记录(id=1),因此我加载AlabamaDictionary.txt,因为该记录来自阿拉巴马州,加载后,启动另一个进程,如地址标准化等。当该进程完成时,我读取下一条记录(id=2),我必须检查“状态”是否相同,是否与之前的状态相同,我不需要再次加载AlabamaDictionary.txt,因为它还没有加载,请启动另一个进程,如地址标准化。当
Records
"id" | "address" | "state"
1 |100 Elm St | Alabama
2 |300 Trawick St | Alabama
3 |50023 N 51st Ave | Arizona
我有下一个循环
代码:
数据表记录
for (int i = 0; i < records.Rows.Count; i++)
{
string address = records.Rows[i][1].ToString();
string state = records.Rows[i][2].ToString();
streetDictionary = state + ".txt";
if(File.Exists(streetDictionary))
{
//Here I need to identify state change,
//so if state change , to use another dictionary and load it,
//but if don't change it (state), I need to use the same dictionary
//(if is load it yet)
LoadStreetDictionary(streetDictionary);
//Process Address Standardization
StreetNameStandardization(address)
}
}
for(int i=0;i
拜托,我怎么做这个循环?
多谢各位 在循环之前定义一个变量
string lastState="";
然后将阅读的词典附在一张支票中,看看你是否仍处于相同的状态
if (!state.equals(lastState))
{
// read the dictionary here
// then...
lastState = state;
}
// check your address here
StreetAddressStandardization();
在循环之前定义一个变量
string lastState="";
然后将阅读的词典附在一张支票中,看看你是否仍处于相同的状态
if (!state.equals(lastState))
{
// read the dictionary here
// then...
lastState = state;
}
// check your address here
StreetAddressStandardization();
您可以将最新状态存储在变量中,并在每次迭代中添加检查
string prevState = string.Empty;
for (int i = 0; i < records.Rows.Count; i++)
{
string address = records.Rows[i][1].ToString();
string state = records.Rows[i][2].ToString();
if (!state.Equals(prevSate))
{
streetDictionary = state + ".txt";
if(File.Exists(streetDictionary))
{
//Here I need to identify state change,
//so if state change , to use another dictionary and load it,
//but if don't change it (state), I need to use the same dictionary
//(if is load it yet)
LoadStreetDictionary(streetDictionary);
}
}
//Process Address Standardization
StreetNameStandardization(address)
prevState = state; //Assigned to latest value
}
string prevState=string.Empty;
for(int i=0;i
编辑:始终执行标准化功能。您可以将最新状态存储在变量中,并在每次迭代中添加检查
string prevState = string.Empty;
for (int i = 0; i < records.Rows.Count; i++)
{
string address = records.Rows[i][1].ToString();
string state = records.Rows[i][2].ToString();
if (!state.Equals(prevSate))
{
streetDictionary = state + ".txt";
if(File.Exists(streetDictionary))
{
//Here I need to identify state change,
//so if state change , to use another dictionary and load it,
//but if don't change it (state), I need to use the same dictionary
//(if is load it yet)
LoadStreetDictionary(streetDictionary);
}
}
//Process Address Standardization
StreetNameStandardization(address)
prevState = state; //Assigned to latest value
}
string prevState=string.Empty;
for(int i=0;i
编辑:始终执行标准化功能。我希望我能正确理解您的要求
String lastState = "";
for (int i = 0; i < records.Rows.Count; i++)
{
string address = records.Rows[i][1].ToString();
string state = records.Rows[i][2].ToString();
streetDictionary = state + ".txt";
if(File.Exists(streetDictionary))
{
if (currentState != state)
LoadStreetDictionary(streetDictionary);
lastState = state;
//Process Address Standardization
StreetNameStandardization(address)
}
}
String lastState=”“;
for(int i=0;i
我希望我能正确理解你的要求
String lastState = "";
for (int i = 0; i < records.Rows.Count; i++)
{
string address = records.Rows[i][1].ToString();
string state = records.Rows[i][2].ToString();
streetDictionary = state + ".txt";
if(File.Exists(streetDictionary))
{
if (currentState != state)
LoadStreetDictionary(streetDictionary);
lastState = state;
//Process Address Standardization
StreetNameStandardization(address)
}
}
String lastState=”“;
for(int i=0;i
谢谢Maku,但不起作用,因为如果我有第一条记录(id=1 state=Alabama),加载Alabama.txt可以正常工作,但在下一条记录(id=2 state=Alabama)中,如果(!state.Equals(prevSate))不允许输入,我需要输入,使用以前加载过的同一个字典(不再加载)抱歉,我错过了这一部分“启动另一个进程,如地址标准化。“。我已更新了我的答案。谢谢Maku,但不起作用,因为如果我有第一条记录(id=1 state=Alabama),加载Alabama.txt效果很好,但在下一条记录(id=2 state=Alabama)中,如果(!state.Equals(prevSate))不让输入,我需要输入,使用以前加载的同一词典(不再加载)抱歉,我错过了这部分”开始另一个过程,比如地址标准化。“。我已经更新了我的答案。谢谢你,但是不起作用,因为如果我有第一个记录(id=1 state=Alabama),加载Alabama.txt会很好,但是在下一个记录(id=2 state=Alabama)中,如果(!state.Equals(prevSate))不让输入,我需要输入,使用以前加载过的同一个字典(不再加载),但这就是重点,你不需要输入。”第二本字典已经读过了,但你还是要读《街道名称标准》