Solved

VB.net v C# Namespace

Posted on 2013-12-14
7
372 Views
Last Modified: 2013-12-14
Hi. I am converting code from C# to VB.net. I notice that in a class module C# always has
"Namespace SAP_Connect_CSharp", while VB.net doesn't. What is this and does VB.net need it?



Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports SAP.Middleware.Connector

Namespace SAP_Connect_CSharp
      Class Customers
            Protected CustomerNo As String
            Protected CustomerName As String
0
Comment
Question by:murbro
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 21

Assisted Solution

by:Dale Burrell
Dale Burrell earned 250 total points
ID: 39718444
Very simply, using a namespace allows you to group you code in a logical manner, within a given namespace all names must be unique, but create a new namespace and you can reuse the names again within the namespace.

There is more to it than that, but that gives you an idea - its a fundamental programming concept.

Couple of links which go into more detail.

http://msdn.microsoft.com/en-us/library/ms973231.aspx

http://msdn.microsoft.com/en-us/library/zt9tafza.aspx
0
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 250 total points
ID: 39718451
while VB.net doesn't.
There is a namespace, you just don't always see it in VB. VB will set a default namespace that is the same name as your project. Your modules would fall under this namespace. You can view your class in the Object Browser to confirm.
0
 

Author Closing Comment

by:murbro
ID: 39718604
Thanks
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Expert Comment

by:Angelp1ay
ID: 39718608
I'm not sure that's quite true kaufmed. My understanding is:
- VB.NET has a root namespace defined on the project which is *added* to anything you put in the class
- C# has a default namespace defined on the project which is written into every class and can be replaced
- Both are initially the project name

Example - if you want your class to be in the namespace "MyProject.DataAccess":
--- VB.NET ---
Project: Root Namespace = MyProject
Class: Namespace DataAccess

--- C#.NET ---
Project: Default Namespace = MyProject
Class: Namespace MyProject.DataAccess

Open in new window

0
 
LVL 40
ID: 39718916
The basic (default) namespace for both language is set to the project's name when you create a new project, but is really defined in the project's Properties window, in the Application tab, and can be changed if needed.

In C#, this default namespace is used by the editor, when you create a new class, while in VB it is used by the compiler, every time you compile.

In C#, you need to specify the namespace at the beginning of each class, so the editor does it for you. If you ever change the namespace in the project's properties later, classes that where already created will keep their old namespace, but new classes added to the project will get the new default.

In VB, you do not have to specify a namespace for each glass, because the compiler will do it for you later. If you change the default, contrary to C#, the namespace is changed everywhere.

Although the notion of namespace is the same in both languages, the way it is implemented in the Visual Studio interface is different.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 39719045
In C#, you need to specify the namespace at the beginning of each class,
This is incorrect. You are not forced to declare a namespace in your class, though the editor does do it for you. Neglecting to specify a namespace in C# means that your class will fall under the global namespace.

It is a best practice to declare a namespace, however.
0
 
LVL 40
ID: 39719156
Right kaumed. This was not stated clearly.

I should have said "need to specify the default namespace if you need the class to fall under it".
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question