February 28, 2021
Hot Topics:

Introducing Microsoft .NET

  • By Anand Narayanaswamy
  • Send Email »
  • More Articles »

About Namespaces

At the top level of the hierarchy is the new concept of namespaces. Namespaces are a group of classes; from these classes are Methods. Basically, namespaces are containers for all classes and are classified into several categories, based on their functionalities. For example, if you need to add records to a database, you need to call several classes, methods, and properties of a namespace called System.Data. This is similar to packages in Java, where we use the Java.sql.* statement. Moreover, all C# programs should call the System namespace. This is the root of all other namespaces in the .NET framework.

Simply putting a statement such as System.Data in your source code will not suffice. You have to apply it by following certain conventions. All namespaces should be called in your programs by applying the keyword using. For example, to call the System namespace, you have to use a statement as shown below:

    using System;

You should end C# statements with a semicolon. Keep in mind that you cannot call Classes along with the using keyword. The using directive applies only to namespaces. Hence, the following code will result in a compilation error:

    using System.Console;

Console is one of the classes in the System namespace. We will use its WriteLine() method for outputting information to the console. However, you can create an alias, as shown in the following code fragment:

    using mysys = System.Console;

Then you have to apply the alias in your program, as shown below:

    mysys.writeLine("Hello C#");

Common Language Specification (CLS)

CLS is a set of rules that a language compiler must adhere to in order to create .NET applications that run in the CLR. If you are going to create a compiler for .NET, you have to adhere to the rules enumerated in the CLS; this enables us to create a club of CLS-compliant languages.

Each such compiler will have the following features:

  • Complete access to the .NET framework hierarchy
  • High level of interoperability with other compliant languages such as Visual Basic .NET, Visual C# .NET and, so forth

For example, a Visual Basic class can inherit from a C# Class and vice versa. You should note that the syntaxes and other programming structures differ a little bit from each of these languages. The only difference is that a developer well versed with a language such as C-Sharp can easily program in Visual Basic .NET or Visual C++ .NET without investing a lot or spending too long to learn a new language. Isn't it exiting?

Related Links

About the Author

Anand Narayanaswamy works as a freelance Web/Software developer and technical writer. He runs and maintains learnxpress.com, and provides free technical support to users. His areas of interest include Web development, Software development using Visual Basic, and in the design and preparation of courseware, technical articles, and tutorials. He can be reached at anand@learnxpress.com.

# # #

Page 3 of 3

This article was originally published on August 22, 2002

Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date