Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions docs/csharp/language-reference/compiler-messages/cs0116.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ ms.assetid: 4cb137b5-ec29-4c1a-adde-9f8424cb9496
---
# Compiler Error CS0116

A namespace does not directly contain members such as fields or methods
A namespace cannot directly contain members such as fields or methods
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


Inside a [namespace](../../../csharp/language-reference/keywords/namespace.md), the compiler only accepts classes, structures, unions, enumerations, interfaces, and delegates. This error is often generated by developers from a C/C++ background who forget that in C#, methods and variables must be declared and defined within a struct or class. For more information, see [General Structure of a C# Program](../../../csharp/programming-guide/inside-a-program/general-structure-of-a-csharp-program.md).
A namespace can contain only other namespaces and type declarations. For more information, see the [namespace keyword](../keywords/namespace.md) article.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A namespace can contain only other namespaces and type declarations

I would prefer the following wording:

Namespaces can contain child namespace and type declarations

??

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@richlander then we need to define the term "child namespace". Moreover, docs rather use "nested namespace" than "child namespace"; I'm not sure if the "child namespace" is an "official" term (language spec uses "nested namespace").

What about:

A namespace can contain nested namespaces and type declarations

?? (though, "contain nested" is a duplication)


This error is often generated by developers from a C/C++ background who forget that in C#, methods and variables must be declared and defined within a struct or class.

## Example

Expand Down Expand Up @@ -40,7 +42,7 @@ namespace x
}
```

## See Also
## See also

- [General Structure of a C# Program](../../../csharp/programming-guide/inside-a-program/general-structure-of-a-csharp-program.md)
- [Classes and Structs](../../../csharp/programming-guide/classes-and-structs/index.md)
Expand Down