Home > Articles > Web Development > Perl

  • Print
  • + Share This
This chapter is from the book

Namespaces

Earlier in this chapter, we introduced the term namespace. In general, all classes in .NET are divided into namespaces to prevent name conflicts. Thus, classes with the same name may reside under the different namespaces. For example, Samples.Car and Examples.Car are different classes with the same name. We may distinguish them by their namespace.

When writing a program, you may refer to classes or types with a fully qualified name, a name in which the namespace precedes the class name. You can specify the fully qualified name either by delimiting the namespace and class name with two colons or by placing the whole name (both namespace and class) in double quotes and delimiting with a dot.

System::Console->WriteLine("Hello");    # Correct
System.Console->WriteLine("Hello");     # Error
"System.Console"->WriteLine("Hello");   # Correct
q(System.Console)->WriteLine("Hello");  # Correct

Throughout the book we specify which namespaces to use in the header of our PerlNET programs with the use namespace pragma.

  • + Share This
  • 🔖 Save To Your Account