The difference about namespace between VB.NET and C#

A

ad

Is there any difference about namespace between VB.NET and C#.



All functions in c# must include in a namespace.

Why I can't find namespace in the files .vb .

How VB.NET implement the concept of namespace
 
J

Jay B. Harlow [MVP - Outlook]

Ad,
Is there any difference about namespace between VB.NET and C#.
No! As namespace is a CLR construct used to groups types.
Why I can't find namespace in the files .vb .
VB.NET projects normally set the Root namespace property under the Project
Properties dialog.

While C# normally leaves the Root namespace property blank under the Project
Properties dialog.

Hope this helps
Jay
 
A

ad

Thank!
But, Why the vb project still can compile after I delete the root namespace
in the project properties dialog,
and I did not add namepace in the codes, so that there are no namespace in
my vb projec?
 
H

Herfried K. Wagner [MVP]

ad said:
But, Why the vb project still can compile after I delete the root
namespace
in the project properties dialog,
and I did not add namepace in the codes, so that there are no namespace in
my vb projec?

This will generate a namespace without a name.
 
J

Jay B. Harlow [MVP - Outlook]

Ad,
Namespaces are not required or as Herfried suggests you can have an unnamed
namespace. As namespaces are simply an organization feature to avoid name
collisions.

In other words in both C# & VB.NET you can leave the root/default namespace
blank, and not to include a namespace statement in the source files. In both
cases you will have an unnamed namespace in the generated assembly.

Doh! Technically C# uses a "Default namespace" that is used when adding new
types. Changing this default namespace does not change existing types.

Hope this helps
Jay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top