This documentation is archived and is not being maintained.

Compiler Error CS1518

Visual Studio 2008

Updated: March 2009

Expected class, delegate, enum, interface, or struct

A declaration was found that is not supported in a namespace. Inside a namespace, the compiler accepts only classes, structs, enums, interfaces, namespaces, and delegates.

The following example generates CS1518.

// CS1518.cs
namespace NS
// OK.
    sealed class c1 {};      
// OK.
    namespace f2 {};         
    // Generates CS1518. A function cannot be defined here.
    public int aFunction() { }




March 2009

Clarified the example.

Customer feedback.