Not all code paths return a value

简介: not all code paths return a value这句话直译是: 不是所有的代码都返回值  private bool aa()  {          foreach (DataRow dr in ds.Tables[0].Rows)          {                  if (dr["列名"].Equals(某个变量))         
not all code paths return a value 这句话直译是: 不是所有的代码都返回值
  private bool aa()
  {
          foreach (DataRow dr in ds.Tables[0].Rows)
          {
                  if (dr["列名"].Equals(某个变量))
                  {
                      return false;
                  }
                  else   if (dr["列名"].Equals(某个变量))
                  {
                     return false;
                  }                    
             }
  }
当涉及到很多if 与else if组成的语句时,如果在每个if或者else中返回值,因为不能保证能执行return语句,结果就会出现错误。
解决办法:
  private bool aa()
  {
          bool bl = true;
          foreach (DataRow dr in ds.Tables[0].Rows)
         {
                if (dr["列名"].Equals(某个变量))
                  {
                      bl = false;
                  }
                  else   if (dr["列名"].Equals(某个变量))
                 {
                      bl = false;
                 }
              }
              return bl;
        }

相关文章
|
XML SQL 数据库
Error getting generated key or setting result to parameter object.必须执行该语句才能获得结果。
Error getting generated key or setting result to parameter object.必须执行该语句才能获得结果。
【已解决】Error: Element type is invalid: expected a string (for built-in components) or a class/function
Error: Element type is invalid: expected a string (for built-in components) or a class/function
2325 0
【已解决】Error: Element type is invalid: expected a string (for built-in components) or a class/function
|
10月前
|
SQL
Parameter ‘id‘ not found. Available parameters are [collection, list]
Parameter ‘id‘ not found. Available parameters are [collection, list]
131 0
|
5月前
|
资源调度
error This module isn‘t specified in a package.json file.
error This module isn‘t specified in a package.json file.
|
5月前
DeprecationWarning:current URL string parser is deprecated, and will be removed in a future version.
DeprecationWarning:current URL string parser is deprecated, and will be removed in a future version.
|
9月前
|
JSON 数据格式
Required request parameter ‘name‘ for method parameter type String is not present 报错解决方法
Required request parameter ‘name‘ for method parameter type String is not present 报错解决方法
3347 0
|
11月前
|
Dart
Dart报The return type ‘bool‘ isn‘t a ‘void‘, as required by the closure‘s context
Dart报The return type ‘bool‘ isn‘t a ‘void‘, as required by the closure‘s context
|
Linux
编译OpenJDK8:error: control reaches end of non-void function [-Werror=return-type]
编译OpenJDK8:error: control reaches end of non-void function [-Werror=return-type]
155 0
Useful code snippet to parse the key value pairs in URL
Useful code snippet to parse the key value pairs in URL
Useful code snippet to parse the key value pairs in URL