C# .Net Tutorial Namespaces, What is a namespace ? Namespace is a container that provides context for the identifiers.
Namespaces are declared using the namespace keyword.
namespace namespace-name {}
A namespace simply provides a named group of classes, structures, enumerations, delegates, interfaces and other namespaces. Within the namespace, all declared items must be uniquely named, .NET environment the namespace keyword is used to declare a scope.
There are almost 13,000 classes in the .NET Framework. This is an overwhelming number. If Microsoft simply jumbled all the classes together, then you would never find anything. Fortunately, Microsoft divided the classes in the Framework into separate namespaces.
A namespace is simply a category.
For example:
All the classes related to working with the file system are located in the System.IO namespace.
All the classes for working a Microsoft SQL Server database are located in the System.Data.SqlClient namespace.
Before you can use a class in a page, you must indicate the namespace associated with the class.
First, you can fully qualify a class name with its namespace. For example, because the File class is contained in the System.IO namespace, you can use the following statement to check whether a file exists:
System.IO.File.Exists(“MyFile.txt”)
A second option is to import a namespace.
You can add an @ Import directive to a page to import a particular namespace, imported the System.Net.Mail namespace because the SmtpClient is part of this namespace.
Includes the following directive near the very top of the page:
@ Import Namespace=”System.Net.Mail”
After you import a particular namespace, you can use all the classes in that namespace without qualifying the class names.
Finally, if you discover that you are using a namespace in multiple pages in your application,then A web configuration file is a special type of file that you can add to your application to configure your application. Be aware that the file is an XML file and, therefore, all the tags contained in the file are case sensitive. You can add a web configuration file to your application by selecting Web Site, Add New Item and selecting Web Configuration “Configuring Applications,” discusses web configuration files in detail.
The ASP.NET Framework gives you the most commonly used namespaces for free. These namespaces are as follows:
. System
. System.Collections
. System.Collections.Specialized
. System.Configuration
. System.Text
. System.Text.RegularExpressions
. System.Web
. System.Web.Caching
. System.Web.SessionState
. System.Web.Security
. System.Web.Profile
. System.Web.UI
. System.Web.UI.WebControls
. System.Web.UI.WebControls.WebParts
. System.Web.UI.HTMLControls
The default namespaces are listed inside the pages element in the root web configuration file located at the following path:
\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG\Web.Config
Namespaces are declared using the namespace keyword.
namespace namespace-name {}
A namespace simply provides a named group of classes, structures, enumerations, delegates, interfaces and other namespaces. Within the namespace, all declared items must be uniquely named, .NET environment the namespace keyword is used to declare a scope.
There are almost 13,000 classes in the .NET Framework. This is an overwhelming number. If Microsoft simply jumbled all the classes together, then you would never find anything. Fortunately, Microsoft divided the classes in the Framework into separate namespaces.
A namespace is simply a category.
For example:
All the classes related to working with the file system are located in the System.IO namespace.
All the classes for working a Microsoft SQL Server database are located in the System.Data.SqlClient namespace.
Before you can use a class in a page, you must indicate the namespace associated with the class.
First, you can fully qualify a class name with its namespace. For example, because the File class is contained in the System.IO namespace, you can use the following statement to check whether a file exists:
System.IO.File.Exists(“MyFile.txt”)
A second option is to import a namespace.
You can add an @ Import directive to a page to import a particular namespace, imported the System.Net.Mail namespace because the SmtpClient is part of this namespace.
Includes the following directive near the very top of the page:
@ Import Namespace=”System.Net.Mail”
After you import a particular namespace, you can use all the classes in that namespace without qualifying the class names.
Finally, if you discover that you are using a namespace in multiple pages in your application,then A web configuration file is a special type of file that you can add to your application to configure your application. Be aware that the file is an XML file and, therefore, all the tags contained in the file are case sensitive. You can add a web configuration file to your application by selecting Web Site, Add New Item and selecting Web Configuration “Configuring Applications,” discusses web configuration files in detail.
The ASP.NET Framework gives you the most commonly used namespaces for free. These namespaces are as follows:
. System
. System.Collections
. System.Collections.Specialized
. System.Configuration
. System.Text
. System.Text.RegularExpressions
. System.Web
. System.Web.Caching
. System.Web.SessionState
. System.Web.Security
. System.Web.Profile
. System.Web.UI
. System.Web.UI.WebControls
. System.Web.UI.WebControls.WebParts
. System.Web.UI.HTMLControls
The default namespaces are listed inside the pages element in the root web configuration file located at the following path:
\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG\Web.Config
Related Topic: |