Export (0) Print
Expand All
Expand Minimize

Compiler Error CS0161

'method': not all code paths return a value

A method that returns a value must have a return statement in all code paths. For more information, see Methods (C# Programming Guide).

The following sample generates CS0161:

// CS0161.cs
public class Test
{
   public static int Main() // CS0161
   {
      int i = 10;
      if (i < 10)
      {
         return i;
      }
      else
      {
         // uncomment the following line to resolve
         // return 1;
      }
   }
}

Community Additions

ADD
Show:
© 2014 Microsoft