The using Directive and the System Namespace

Filed in ASP.NETTags: , , , ,

As we know a namespaces is a set of related classes. A namespace may also contain other namespaces. Today we will discuss about the System namespace. The System namespace contains the classes that most applications use for interacting with the operating system. You can refer to objects in namespaces by prefixing them explicitly with the identifier of the namespace. For example the System namespace contains the Console class, which provides several methods, including WriteLine.




You can access the WriteLine method of the Console class as follows:

System.Console.WriteLine(“Hello”);

 

Using Directive:  We can specify a namespace by placing a using directive at the beginning of our application before the first class is defined. We use the using directive so that we need not to write the namespace name always when we want to use any method of that particular class. A using directive specifies a namespace that will be examined if a class is not explicitly defined in the application. We can also use more than one using directive but all these should be putting on the top before the first class is used. Here are some example :

Using System;

Using System.Data;

After specify the namespace with using directive at the top now we can use the method of that namespace directly using the following example:

Console.WriteLine(“Hello”);

Sourabh Sharma (150 Posts)


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>