Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
A type that is not defined in a named namespace is called a "top level type". A namespace not defined in a named namespace is called a top level namespace. Hence a type not defined in a named namedspace is called a top level type.

public class TopLevelType
{
    //body
}



A type that is defined within a type is called a "nested type".

namespace SampleNamespace
{
    public class ClassFoo
    {
        public class NestedType
        {
            //body
        }
    }
}



But what do you call a type that is simply defined within a named namespace? Is there a special name given to it just as with the others?

namespace SampleNamespace
{
    public class ClassFoo
    {
        //body
    }
}


What I have tried:

C# Language
Visual Studio
C# 9.0 and below
Posted
Updated 5-Sep-21 14:37pm
v2

No, there's no special name.

It's just a "type", no matter where it's defined.

*
 
Share this answer
 
Comments
CBennigton 6-Sep-21 3:06am    
As for what is a "top level type". Even though it's not an official C# term such a term its seems correct that a type defined directly under the global namespace (not in a named namespace) is called a top level type. Since as stated a namespace defined directly under the global namespace is called top level namespace.

Not sure if you agree with that, what do you think?
Dave Kreskowiak 6-Sep-21 9:56am    
You can call it whatever you want. Just don't try to talk to someone using that term because nobody will know what you're talking about.
Quote:
But what do you call a type that is simply defined within a named namespace? Is there a special name given to it just as with the others?
You cannot create Types that are not "in" some NameSpace.

It may appear you can, but, such Types, not in the scope of a "visible" NameSpace, end up in the the global/root/default NameSpace: [^], [^], [^].

I consider any use of the global namespace that is not explicit to be a sign of poor programming.
 
Share this answer
 
Comments
CBennigton 6-Sep-21 3:07am    
As for what is a "top level type". Even though it's not an official C# term such a term its seems correct that a type defined directly under the global namespace (not in a named namespace) is called a top level type. Since as stated a namespace defined directly under the global namespace is called top level namespace.

Not sure if you agree with that, what do you think?
BillWoodruff 6-Sep-21 3:40am    
You can call it what you like :) I prefer to use the MS terms. 'root, 'default, 'global.

Keep in mind the "existential" difference between NameSpaces you declare, and the invocation of NameSpaces which 'Using statements activate by loadinf dll's.
BillWoodruff 6-Sep-21 8:42am    
upcoming features of 'using in .NET 6:

https://dotnetcoretutorials.com/2021/08/31/implicit-using-statements-in-net-6/?utm_source=.NET+Core+Tutorials
CBennigton 7-Sep-21 20:44pm    
If I may add on one more final detail to this discussion, a well known C# programmer by the name of Jon Skeet even uses the term "top level type".

If you look at his solution https://stackoverflow.com/a/9443365 in the following Stack Over Flow post he actually refers to the class defined directly under the global namespace as the "top level type" rather than the class defined under named namespace Foo as the top level type.

Which as a result, is another reason that has led me to believe that only types (structs, enums, classes, interfaces or delegates) defined directly under the global namespace (e.g. global::TopLevelType) and thus, not referring to types defined in a named namespace, are called "top level types".

You are probably already annoyed by me asking these kinds of questions but if you can give me your insight on what I mentioned above (if anything that is) i'd appreciate it. Thank you for your time. I hope to hear from you soon.

BillWoodruff 7-Sep-21 20:58pm    
Hi, More stunned than "annoyed" :)

If you are reading Jon Skeet, Eric Lippert, Mads Torgersen, Michaelis, Troelsen, et. al., you are at the right place (sorry for any misspellings).

I have no opinion on the issue you describe, but, Delegates as global sounds "off."

This IS the book you need;

https://www.oreilly.com/library/view/the-c-programming/9780132484718/

https://www.amazon.com/Programming-Language-Covering-Portable-Documents-ebook/dp/B004BSFKXY

The annotations by "Brad Abrams, Joseph Albahari, Krzysztof Cwalina, Jesse Liberty, Eric Lippert, Christian Nagel, Vladimir Reshetnikov, Marek Safar, Chris Sells, Peter Sestoft, Jon Skeet, and Bill Wagner" are pure gold.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900