The .NET System Namespace
- Libraries Shared Across Languages
- Namespaces in C++
- The System Namespace
- Other Useful Namespaces
- In Brief
In This Chapter
Libraries Shared Across Languages
Namespaces in C++
The System Namespace
Other Useful Namespaces
In Brief
Libraries Shared Across Languages
When you write managed C++, you have access to all of the managed code libraries that come with the .NET Framework: the Base Class Libraries, ADO.NET, ASP.NET, and so on. These libraries are modern and powerful. They provide services, such as XML processing, that weren't even thought of when older libraries such as MFC and ATL were first written.
In sharp contrast to the historical capabilities of C++ and Visual Basic, on the .NET Framework these two languages share the same class libraries. Every library class and method that's available from Visual Basic is available from managed C++ and from C#. Every library class and method that's available from C# is available from Visual Basic and Managed C++.
The advantages of a shared class library are many. They include
-Reduced learning time when moving from one .NET-supported language to another
-A larger body of samples and documentation, because these do not need to be language specific
-Better communication between programmers who work in different .NET-supported languages
The C++ Advantage
C++ can use the same class libraries as C# and VB.NET. Does it work the other way around? No. There are libraries of unmanaged code available from managed C++ that cannot be called from Visual Basic or C#ATL and MFC are just two examples. However, it's unlikely that a Visual Basic or C# programmer would want to use those libraries, because their functionality is provided elsewhere; the capability to call them from managed C++ helps simplify a port from unmanaged to managed C++.
Working in Multiple Languages
I have a small consulting firm, and often our clients specify the programming language we are to use for a project. When several projects are on the go at once, I might switch languages several times in the course of a single day, as I help my associates with problems or track down the last few bugs in systems that are almost finished.
Before I starting using the .NET Framework, about once a month I'd suffer a "brain freeze" and for a moment or two forget how to perform some really simple task, like determining whether a string contains a particular character, in the language of the moment. Usually at those times my fingers would start typing the method or operator in randomly chosen other languages or libraries: Perl, Visual Basic, MFC, STL, Javaanything except the one I wanted. Now, with a common set of libraries across languages, I don't have to "context switch" nearly as oftenand I avoid those "deer in the headlights" moments.
In the past, just because you knew how to perform a specific task, such as writing some text to a file in Visual C++, didn't mean you knew how to do that same task in Visual Basic. A great tutorial you found on database access in Visual Basic wasn't much help if you wanted to write your database application in Visual C++. Now, as long as you're working in managed C++, the walkthroughs, tutorials, and samples you find for any managed languageand you'll find plenty for Visual Basic and C#are equally applicable to Visual C++. You'll have to translate the actual language elements, of course, but an explanation of a particular class or a method of that class is valid no matter which .NET supported language you intend to use.