title: Not all code paths return a value in C# console application Error Coode:CS0161
body: <p>I have the return statement for both if and else conditions within a foreach loop. Yet, I get this error. However, when I add a return statement after the loop ends, the error is resolved. That's fine! But what is a problem with the code below?  </p>
  
  <pre><code>public static bool Function(List&lt;String&gt; list)
  {
      foreach (var item in list)
      {
          if(item != "test")
          {
              return false;
          }
          else
          {
              return true;
          }
      }
      //return false
  }
  </code></pre>