Expand Minimize
7 out of 79 rated this helpful - Rate this topic

Compiler Error CS0118 

Error Message

'construct1_name' is a 'construct1' but is used like a 'construct2'

The compiler detected a situation in which a construct was used in some erroneous way or a disallowed operation was attempted on a construct. Some common examples include:

  • An attempt to instantiate a namespace (rather than a class)

  • An attempt to call a field (rather than a method)

  • An attempt to use a type as a variable

  • An attempt to use an extern alias as a type.

To resolve this error, make sure the operation you are performing is valid for the type you are performing the operation on.

Example

The following sample generates CS0118.

// CS0118.cs
// compile with: /target:library
namespace MyNamespace
{
   class MyClass
   {
      // MyNamespace not a class
      MyNamespace ix = new MyNamespace ();   // CS0118
   }
}
Did you find this helpful?
(1500 characters remaining)

Community Additions

ADD
© 2013 Microsoft. All rights reserved.