A Brief Tour of the .NET Framework Namespaces

122 Private Sub DisposeManagedResources Call subordinate objects Dispose methods. End Sub Private Sub DisposeUnmanagedResources Release unmanaged resources, such as database connections. End Sub Private Sub DoSomething Call the EnsureNotDisposed method at the top of every method that needs to access the resources held by the object. EnsureNotDisposed ... End Sub Private Sub EnsureNotDisposed Make sure that the object hasnt been disposed. Instead of throwing an exception, this method could be written to reacquire the resources that are needed by the object. If disposed Then Throw New ObjectDisposedExceptionMe.GetType .Name End If End Sub End Class

3.10 A Brief Tour of the .NET Framework Namespaces

The .NET Framework provides a huge class library—something on the order of 6,000 types. To help developers navigate though the huge hierarchy of types, Microsoft has divided them into namespaces. However, even the number of namespaces can be daunting. Here are the most common namespaces and an overview of what they contain: Microsoft.VisualBasic Runtime support for applications written in Visual Basic .NET. This namespace contains the functions and procedures included in the Visual Basic .NET language. Microsoft.Win32 Types that access the Windows Registry and provide access to system events such as low memory, changed display settings, and user logout. System Core system types, including: • Implementations for Visual Basic .NETs fundamental types see Types in Chapt er 2 for a list of fundamental types and the .NET classes that implement them. • Common custom attributes used throughout the .NET Framework class library see Appendix A , as well as the Attribute class, which is the base class for most although not all custom attributes in .NET applications. • Common exceptions used throughout the .NET Framework class library see Appendix B , as well as the Exception class, which is the base class for all exceptions in .NET applications. 123 • The Array class, which is the base class from which all Visual Basic .NET arrays implicitly inherit. • The Convert class, which contains methods for converting values between various types. • The Enum class, from which all enumerations implicitly derive. • The Delegate class, from which all delegates implicitly derive. • The Math class, which has many shared methods for performing common mathematical functions e.g., Abs, Min, Max, Sin, and Cos. This class also defines two constant fields, E and PI, that give the values of the numbers e and pi , respectively, within the precision of the Double data type. • The Random class, for generating pseudorandom numbers. • The Version class, which encapsulates version information for .NET assemblies. System.CodeDom Types for automatically generating source code used by tools such as the wizards in Visual Studio .NET and by the ASP.NET page compiler. System.Collections Types for managing collections, including: ArrayList Indexed like a single-dimensional array and iterated like an array, but much more flexible than an array. With an ArrayList, it is possible to add elements without having to worry about the size of the list the list grows automatically as needed, insert and remove elements anywhere in the list, find an elements index given its value, and sort the elements in the list. BitArray Represents an array of bits. Each element can have a value of True or False . The BitArray class defines a number of bitwise operators that operate on the entire array at once. Hashtable Represents a collection of keyvalue pairs. Both the key and value can be any object. Queue Represents a queue, which is a first-in-first-out FIFO list. SortedList Like a Hashtable, represents a collection of keyvalue pairs. When enumerated, however, the items are returned in sorted key order. In addition, items can be retrieved by index, which the Hashtable cannot do. Not surprisingly, SortedList operations can be slower than comparable Hashtable operations because of the increased work that must be done to keep the structure in sorted order. Stack Represents a stack, which is a last-in-first-out LIFO list. 124 Be aware that in addition to these types, there is also the Array type, defined in the System namespace, and the Collection type, defined in the Microsoft.VisualBasic namespace. The latter is a collection type that mimics the behavior of Visual Basic 6 collection objects. System.ComponentModel Support for building components that can be added to Windows Forms and Web Forms. System.Configuration Support for reading and writing program configuration. System.Data Support for data access. The types in this namespace constitute ADO.NET. System.Diagnostics Support for debugging and tracing. System.Drawing Graphics-drawing support. System.EnterpriseServices Transaction-processing support. System.Globalization Internationalization support. System.IO Support for reading and writing streams and files. System.Net Support for communicating over networks, including the Internet. System.Reflection Support for runtime type discovery. System.Resources Support for reading and writing program resources. System.Security Support for accessing and manipulating security information. System.ServiceProcess Types for implementing system services. 125 System.Text Types for manipulating text and strings. Note in particular the StringBuilder type. When strings are built from smaller parts, the methods on the StringBuilder class are more efficient than similar methods on the String class. This is because the instances of the String class cant be modified in place; every time a change is made to a String object, a new String object is actually created to hold the new value. In contrast, the methods in StringBuilder that modify the string actually modify the string in place. System.Threading Support for multithreaded programming. System.Timers Provides the Timer class, which can generate an event at predetermined intervals. This addresses one of the limitations of the Visual Basic 6 Timer control: it had to be hosted in a container and therefore could be used only in an application with a user interface. System.Web Support for building web applications. The types in this namespace constitute Web Forms and ASP.NET. System.Windows.Forms Support for building GUI fat client applications. The types in this namespace constitute Windows Forms. System.Xml Support for parsing, generating, transmitting, and receiving XML.

3.11 Configuration