what is the difference between these two exection commands in c#

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-12 02:58:17

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!