Export (0) Print
Expand All
Expand Minimize

Compiler Error CS0119

'construct1_name' denotes a 'construct1' which is not valid in the given context

The compiler detected an unexpected construct. For example:

  • A class constructor is not a valid test expression in a conditional statement.
  • A class name was used instead of an instance name to refer to an array element.

The following sample generates CS0119:

// CS0119.cs
namespace a
{
   public class z
   {
      public z()
      {
      }

      public static void Main()
      {
         (z()) ? 0 : 1;  // CS0119, cannot use constructor in a conditional statement
         // the following line is a more acceptable conditional statement
         // 1 < 2 ? 0 : 1;
      }
   }
}
Show:
© 2014 Microsoft