X hits on this document

PDF document

“Beginning Visual C# 2005 Express Edition Video Series” - page 61 / 73





61 / 73

Namespaces in your Applications

When you create an applications using Visual Studio.NET, a default namespace will be automatically created. Suppose you create a new project and you name it “MyProgram”. The root namespace for your application is called “MyProgram” and if you add a class to your application called “MyClass”, the fully- qualified name of the class would be “MyProgram.MyClass”. Why do you need namespaces in your applications? This prevents a naming conflict between the names of your classes and the names of classes in the .NET Framework Class Library. Suppose you create a class in your application called Format. You may not realize it, but there is a class called Format in the .NET Framework class library, too! Without providing a “middle name and a surname” (just like people have to distinguish them from one another) for our class, the compiler would have no idea which class to create an instance of. That is why your Format class is automatically assigned the name “MyProgram.Format” which differentiates it from the “System.Windows.Forms.DataFormats.Format” class.

Also, if you or your company are responsible for creating a re- usable class library (a .DLL file, or rather, Assembly that can be shared across one or more applications), a namespace will prevent a naming conflict between your class library and one created by someone else that is used within the same application.

You can change the root namespace for your project in the Project Properties dialog in the Common Properties tab. You also can define as many namespaces in code as you want to using the following structure:

Supplemental Readings for the Express Edition Videos Copyright © 2005 LearnVisualStudio.NET


Document info
Document views262
Page views262
Page last viewedSun Jan 22 02:17:36 UTC 2017