Skip to content

Conversation

@pkulikov
Copy link
Contributor

According to the namespace article, namespace can contain another namespace and no mention of unions.

What is "unions" in

Inside a namespace, the compiler only accepts classes, structures, unions, enumerations, interfaces, and delegates.

by the way?

@pkulikov pkulikov requested a review from BillWagner as a code owner November 23, 2018 23:39
@svick
Copy link
Contributor

svick commented Nov 24, 2018

What is "unions" […] by the way?

In C++, apart from classes, structs and enums, you can also have unions as another type kind. And since the article says:

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.

My guess is that:

This error was generated by a writer from a C/C++ background who forgot that in C#, unions don't exist.

😉

# 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.

A namespace cannot directly contain members such as fields or methods

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)

Copy link
Member

@BillWagner BillWagner left a comment

Choose a reason for hiding this comment

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

This LGTM @pkulikov

Thanks for updating based on @richlander 's comments.

I'll :shipit: now.

@BillWagner BillWagner merged commit 0158062 into dotnet:master Nov 26, 2018
@pkulikov pkulikov deleted the patch-5 branch November 26, 2018 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants