Namespaces


.NET types are organized in namespaces. The syntax for defining and using namespaces is quite different with the three languages.

To import namespaces, C# uses the using keyword. C++/CLI is fully based on the C++ syntax with the using namespace statement. Visual Basic defines the Imports keyword to import namespaces.

With C#, you can define an alias to classes or other namespaces. With C++/CLI and Visual Basic namespace, an alias can only reference other namespaces, but not classes. C++ requires the namespace keyword to define an alias - the same keyword is used to define a namespace. Visual Basic uses the Imports keyword again.

For defining namespaces, all three languages use the namespace keyword, but there’s still a difference. With C++/CLI, you can’t define hierarchical namespaces with one namespace statement; instead the namespaces must be nested. There’s one important difference with the project settings: defining a namespace in the project settings of C# defines a default namespace that shows up in the code of all new items that you add to the project. With Visual Basic project settings, you define the root namespace that is used by all items in the project. Namespaces declared in the source code only define the subnamespace inside the root namespace.

  // C# using System; using System.Collections.Generic; using Assm = Wrox.ProCSharp.Assemblies; namespace Wrox.ProCSharp.Languages { } // C++/CLI using namespace System; using namespace System::Collections::Generic; namespace Assm = Wrox.ProCSharp.Assemblies; namespace Wrox {    namespace ProCSharp    {       namespace Languages       {       }    } } ' Visual Basic Imports System Imports System.Collections.Generic Imports Assm = Wrox.ProCSharp.Assemblies Namespace Wrox.ProCSharp.Languages End Namespace 




Professional C# 2005 with .NET 3.0
Professional C# 2005 with .NET 3.0
ISBN: 470124725
EAN: N/A
Year: 2007
Pages: 427

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net