问题
Do you know the difference between these two conditions?
1
if(reader.hasrows())
{
while(reader.read())
{
}
}
2
while(reader.read())
{
if(reader.hasrows())
{
}
}
回答1:
Doing if/while or while/if is not necessary, since "while(reader.read())" will only return true when the reader has rows "hasrows()" and has a row to read "read()". The extra nesting has no value.
来源:https://stackoverflow.com/questions/3098572/what-is-the-difference-between-these-two-exection-commands-in-c-sharp