Namespace is logical division of class, structure and interface OR way to organize your Visual Basic .NET code is through the use of namespaces.
Namespaces are a way of grouping type names and reducing the chance of name collisions.
The namespace with all the built-in functionality comes under System namespace. All other namespaces comes under this System namespace.
Syntax of Namespace :
// Namespace Declaration using System;
// The C# Station Namespace namespace csharp_station { // Program start class class NamespaceCSS { // Main begins program execution. public static void Main() { // Write to console Console.WriteLine("This is the new C# Station Namespace."); } } }
Use of Namespace : It is somehow like this, For example if you are making an application on - "Binding A Gridview", surely you will use SQL server Database, so to call the table and your database , you will write code for that in .CS file, at that you have to import namespace: - using system.data using system.data.SqlClient
By default in.cs file Visual Studio had already imported some namespace for you.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
Thank you . Mark Accepted if you satisfy with any answer from any member given below.
A namespace is designed for providing a way to keep one set of names separate from another. The class names declared in one namespace does not conflict with the same class names declared in another.
Think of namespaces as boxes with name on the top and all the classes relevant to that box are put in the box. so when we open a box (use namespace), we can use all the classes associated with that box.
Benefits of having namespace:
1) if we have 2 classes with same name, we can still use them as long as they both belong to different boxes (namespace) - you cannot have only one class with the same name.
2) Another advantage of having namespace, developers can now create classes with same name and put it under their custom namespace, had there not been namespaces - there wouldn't had been so many .NET framework classes under different namespace.
Namespace can be define as a Collection of classes and Objects which is used to keep separate one set of names from another.The class or Method define in one Namespace will not conflict with class and methods define in another namespace.
Namespaces allow you to create a system to organize your code. A good way to organize your namespaces is via a hierarchical system. You put the more general names at the top of the hierarchy and get more specific as you go down. This hierarchical system can be represented by nested namespaces.By placing code in different sub-namespaces, you can keep your code organized.
Nilesh JadavPosted Jun 19, 2015, 8:14 AM
Namespace:
Syntax of Namespace :
// Namespace Declaration
Use of Namespace : It is somehow like this, For example if you are making an application on - "Binding A Gridview", surely you will use SQL server Database, so to call the table and your database , you will write code for that in .CS file, at that you have to import namespace: - using system.datausing System;
// The C# Station Namespace
namespace csharp_station
{
// Program start class
class NamespaceCSS
{
// Main begins program execution.
public static void Main()
{
// Write to console
Console.WriteLine("This is the new C# Station Namespace.");
}
}
}
using system.data.SqlClient
By default in.cs file Visual Studio had already imported some namespace for you.
Thank you . Mark Accepted if you satisfy with any answer from any member given below.
Rajeesh MenothPosted Jun 19, 2015, 2:31 AM
Upendra Pratap ShahiPosted Jun 19, 2015, 12:38 AM
Hussain PatelPosted Jun 18, 2015, 11:33 AM
Julin JamesPosted Jun 18, 2015, 9:34 AM
Julin JamesPosted Jun 18, 2015, 9:31 AM
Pankaj Kumar ChoudharyPosted Jun 12, 2015, 8:32 AM
Lalit RaghavPosted Jun 12, 2015, 8:19 AM
Upendra Pratap ShahiPosted Jun 12, 2015, 7:35 AM
Need for Namespaces
Namespaces allow you to create a system to organize your code. A good way to organize your namespaces is via a hierarchical system. You put the more general names at the top of the hierarchy and get more specific as you go down. This hierarchical system can be represented by nested namespaces.By placing code in different sub-namespaces, you can keep your code organized.