Avatar of cdemott33
cdemott33
Flag for United States of America asked on

Classes and Namespace

Newbie question.  When you create a Class in Visual Studio I right-click the 'AppCode' folder, select 'Class' and name the class "Customers".  It throw the Customers.vb file in my 'AppCode' folder.  Great.

Here's my question?  When you create a Class file, such as "Customer.vb" does the NameSpace have to MATCH or can it be name differently?

I've been doing some research on naming convensions and what I've found online says that your namespace should be something like this:

CompanyName.Customers.DataLayer

If that's the case, should my Class file be renamed from "Customers.vb" to "CompanyName.Customers.DataLayer.vb"

Hope this makes sense.  I just confused on the correct way to do it and if they need to match.  Please help!
.NET ProgrammingVisual Basic ClassicASP.NET

Avatar of undefined
Last Comment
cdemott33

8/22/2022 - Mon
jmwheeler

No, you do not need to rename your class file.  A Namespace is more or less a way to group things for finding them easier.  Using the naming convention below you would not rename your class file, just make it look like this:


namespace CompanyName.Customers.DataLayer
{
    public class Customer
    {
        //Your class code
    }
}

Open in new window

cdemott33

ASKER
Thank you for your answer.  One last question which is related to the subject.  Can you have multiple namespaces under the same class file?
cdemott33

ASKER
... In other words, can I do something like this?


Namespace CompanyName.Customers.DataLayer
    Public Class Customers
         Function goes here... etc. etc.
    End Class
End Namespace
 
Namespace CompanyName.Buyers.DataLayer
    Public Class Customers
      Function goes here... etc. etc.
    End Class
End Namespace

Open in new window

Your help has saved me hundreds of hours of internet surfing.
fblack61
ASKER CERTIFIED SOLUTION
jmwheeler

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
cdemott33

ASKER
Thank You!