< .Net Framework Class Library 2 | Main | .Net Framework Class Library 4 >


 

 

The .NET Framework Class Library Review 3

 

 

 

 

 

The topics in this part are listed below. The code snippets if any are based on the new C++ .NET syntaxes. The code snippets if any are based on the new C++ .NET syntaxes.

  1. The .NET Framework Namespaces

  2. Using Namespaces in C++ Programs

  3. The System Namespace

  4. System Classes

 

 

The .NET Framework Namespaces

 

Namespaces is a logical naming scheme for grouping related types. The logical is seen or used by system/program and the physical seen or used by human. The .NET Framework uses a hierarchical naming scheme for grouping types into logical categories of related functionality, such as the ASP.NET technology or remoting functionality. Design tools can use namespaces to make it easier for developers to browse and reference types in their code. A single assembly can contain types whose hierarchical names have different namespace roots, and a logical namespace root can span multiple assemblies. In the .NET Framework, a namespace is a logical design-time naming convenience, whereas an assembly establishes the name scope for types at run time.

The .NET Framework class library is made up of a set of classes, interfaces, structures, and enumerations that are contained in almost 100 namespaces. This section begins by trying to explain how to use namespaces in managed C++ code and then goes on to list the major .NET namespaces, together with brief details of their function and content. You’ve already encountered .NET namespaces in use in managed C++ code when you’ve used the C++ using keyword, as in the following example:

 

using namespace System::Collections;

 

As with traditional C++ namespaces, .NET namespaces provide an additional level of scoping that helps you organize code and guard against name clashes. Two classes with the same name can be used in a program, provided that they belong to different namespaces. A type name that includes the namespace information is called the fully qualified name, as in the examples shown here:

 

System::Collections::ArrayList  // the ArrayList class from System::Collections

System::Threading::Thread       // the Thread class from System::Threading

 

Namespace names in .NET typically consist of more than one word. In managed C++, the components of the name are separated by the scope resolution operator (::). In other .NET languages such as C# and Visual Basic .Net, the components are separated using a period (.), so in Visual Basic .Net, the preceding examples would be:

 

System.Collections.ArrayList
System.Threading.Thread

 

 

All classes, interfaces, structures, and enumerations that are part of the .NET Framework class library belong to a namespace. All the namespaces provided by Microsoft begin with one of two prefixes:

  1. Those that start with System have been developed as part of the .NET Framework class library.

  2. Those beginning with Microsoft have been developed by other product groups within Microsoft.

Namespace names can have any number of components, but there’s no hierarchical relationship implied in names that contain the same root components. The hierarchical nature of namespace names simply gives you a way to organize your classes. So, for example, System::Collections::Specialized and System::Collections both contain collections, yet they aren’t necessarily related in any other way.

Although .NET namespaces look very much like Java package names, there’s no relationship between namespace names and directory paths as there is in Java. There’s no requirement that all the classes belonging to one namespace are defined in the same DLL or that a single DLL contains classes from only one namespace.

 

Using Namespaces in C++ Programs

 

Managed C++ programs use the #using preprocessor directive to import metadata into a program using the Managed Extensions for C++. Remember that metadata is information that describes the types in an assembly, and it includes the fully qualified names of all the types. For example, if the compiler sees a line such as:

#using <mscorlib.dll>

It loads the DLL and reads the metadata for all the types that are defined there. Because mscorlib.dll contains most of the core .NET Framework classes, it imports the metadata for a very large number of types. Fortunately the new version C++ (VC+ + 2005) already included the <mscorlib.lib> automatically. So, no need to put it in your program and included in this module for completeness.

The #using keyword means that you have to know which DLL holds the class or classes you want to use. Your normal source for this information will be the online help, and whenever we mention a namespace in the rest of this module, we’ll also say which DLL it belongs to.  Some of the fully qualified names can get rather long. Thus, it’s common to use a traditional using directive to specify namespace names so that you can use unqualified names, as shown here:

// Read the metadata for MSCORLIB

#using <mscorlib.dll>

 

// Import all the names

using namespace System::Collections;

 

// Now you can use ArrayList without having to qualify it

ArrayList^ pal = gcnew ArrayList();

The System Namespace

 

The System namespace, defined in mscorlib.dll, contains a lot of fundamental classes that include:

  1. Base classes for commonly used value and reference types, plus the base class for arrays.

  2. Events and event handlers.

  3. Delegates and interfaces.

  4. Attributes.

  5. Exceptions.

  6. Math.

  7. Application environment management.

  8. Garbage collection.

  9. Local and remote program invocation.

  10. Data type conversion.

 

The System namespace contains fundamental classes and base classes that define commonly-used value and reference data types, events and event handlers, interfaces, attributes, and processing exceptions. Other classes provide services supporting data type conversion, method parameter manipulation, mathematics, remote and local program invocation, application environment management, and supervision of managed and unmanaged applications. Information for the System namespace is given in the following section (and for other namespaces details and updates, please refer to MSDN or your compiler documentation, only summaries are provided here). As defined in C and C++ Tutorial, a class is a reference type that encapsulates data (constants and fields) and behavior (methods, properties, indexers, events, operators, instance constructors, static constructors, and destructors), and can contain nested types. Class types support inheritance, a mechanism whereby a derived class can extend and specialize a base class. Let explore the classes, interfaces, structures, delegates and enumerations available in System namespace.

 

System Classes

 

Class

Description

Symbol

The class symbol used in VC++ .NET

AccessViolationException

The exception that is thrown when there is an attempt to read or write protected memory.

ActivationContext

Identifies the activation context for the current application. This class cannot be inherited.

Activator

Contains methods to create types of objects locally or remotely, or obtain references to existing remote objects. This class cannot be inherited.

AppDomain

Represents an application domain, which is an isolated environment where applications execute. This class cannot be inherited.

AppDomainManager

Provides a managed equivalent of an unmanaged host.

AppDomainSetup

Represents assembly binding information that can be added to an instance of AppDomain.

AppDomainUnloadedException

The exception that is thrown when an attempt is made to access an unloaded application domain.

ApplicationException

The exception that is thrown when a non-fatal application error occurs.

ApplicationId

Contains information used to uniquely identify an application. This class cannot be inherited.

ApplicationIdentity

Provides the ability to uniquely identify a manifest-activated application. This class cannot be inherited.

ArgumentException

The exception that is thrown when one of the arguments provided to a method is not valid.

ArgumentNullException

The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method that does not accept it as a valid argument.

ArgumentOutOfRangeException

The exception that is thrown when the value of an argument is outside the allowable range of values as defined by the invoked method.

ArithmeticException

The exception that is thrown for errors in an arithmetic, casting, or conversion operation.

Array

Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the base class for all arrays in the common language runtime.

ArrayTypeMismatchException

The exception that is thrown when an attempt is made to store an element of the wrong type within an array.

AssemblyLoadEventArgs

Provides data for the AssemblyLoad event.

Attribute

Represents the base class for custom attributes.

AttributeUsageAttribute

Specifies the usage of another attribute class. This class cannot be inherited.

BadImageFormatException

The exception that is thrown when the file image of a DLL or an executable program is invalid.

BitConverter

Converts base data types to an array of bytes, and an array of bytes to base data types.

Buffer

Manipulates arrays of primitive types.

CannotUnloadAppDomainException

The exception that is thrown when an attempt to unload an application domain fails.

CharEnumerator

Supports iterating over a String object and reading its individual characters. This class cannot be inherited.

CLSCompliantAttribute

Indicates whether a program element is compliant with the Common Language Specification (CLS). This class cannot be inherited.

Console

Represents the standard input, output, and error streams for console applications. This class cannot be inherited.

ConsoleCancelEventArgs

Provides data for the Console.CancelKeyPress event. This class cannot be inherited.

ContextBoundObject

Defines the base class for all context-bound classes.

ContextMarshalException

The exception that is thrown when an attempt to marshal an object across a context boundary fails.

ContextStaticAttribute

Indicates that the value of a static field is unique for a particular context.

Convert

Converts a base data type to another base data type.

DataMisalignedException

The exception that is thrown when a unit of data is read from or written to an address that is not a multiple of the data size. This class cannot be inherited.

DBNull

Represents a null value.

Delegate

Represents a delegate, which is a data structure that refers to a static method or to a class instance and an instance method of that class.

DivideByZeroException

The exception that is thrown when there is an attempt to divide an integral or decimal value by zero.

DllNotFoundException

The exception that is thrown when a DLL specified in a DLL import cannot be found.

DuplicateWaitObjectException

The exception that is thrown when an object appears more than once in an array of synchronization objects.

EntryPointNotFoundException

The exception that is thrown when an attempt to load a class fails due to the absence of an entry method.

Environment

Provides information about, and means to manipulate, the current environment and platform. This class cannot be inherited.

EventArgs

EventArgs is the base class for classes containing event data.

Exception

Represents errors that occur during application execution.

ExecutionEngineException

The exception that is thrown when there is an internal error in the execution engine of the common language runtime. This class cannot be inherited.

FieldAccessException

The exception that is thrown when there is an invalid attempt to access a private or protected field inside a class.

FileStyleUriParser

A customizable parser based on the File scheme.

FlagsAttribute

Indicates that an enumeration can be treated as a bit field; that is, a set of flags.

FormatException

The exception that is thrown when the format of an argument does not meet the parameter specifications of the invoked method.

FtpStyleUriParser

A customizable parser based on the File Transfer Protocol (FTP) scheme.

GC

Controls the system garbage collector, a service that automatically reclaims unused memory.

GenericUriParser

A customizable parser for a hierarchical URI.

GopherStyleUriParser

A customizable parser based on the Gopher scheme.

HttpStyleUriParser

A customizable parser based on the HTTP scheme.

IndexOutOfRangeException

The exception that is thrown when an attempt is made to access an element of an array with an index that is outside the bounds of the array. This class cannot be inherited.

InsufficientMemoryException

The exception that is thrown when a check for sufficient available memory fails. This class cannot be inherited.

InvalidCastException

The exception that is thrown for invalid casting or explicit conversion.

InvalidOperationException

The exception that is thrown when a method call is invalid for the object's current state.

InvalidProgramException

The exception that is thrown when a program contains invalid Microsoft intermediate language (MSIL) or metadata. Generally this indicates a bug in the compiler that generated the program.

LdapStyleUriParser

A customizable parser based on the Lightweight Directory Access Protocol (LDAP) scheme.

LoaderOptimizationAttribute

Used to set the default loader optimization policy for the main method of an executable application.

LocalDataStoreSlot

Encapsulates a memory slot to store local data. This class cannot be inherited.

MarshalByRefObject

Enables access to objects across application domain boundaries in applications that support remoting.

Math

Provides constants and static methods for trigonometric, logarithmic, and other common mathematical functions.

MemberAccessException

The exception that is thrown when an attempt to access a class member fails.

MethodAccessException

The exception that is thrown when there is an invalid attempt to access a private or protected method inside a class.

MissingFieldException

The exception that is thrown when there is an attempt to dynamically access a field that does not exist.

MissingMemberException

The exception that is thrown when there is an attempt to dynamically access a class member that does not exist.

MissingMethodException

The exception that is thrown when there is an attempt to dynamically access a method that does not exist.

MTAThreadAttribute

Indicates that the COM threading model for an application is multithreaded apartment (MTA).

MulticastDelegate

Represents a multicast delegate; that is, a delegate that can have more than one element in its invocation list.

MulticastNotSupportedException

The exception that is thrown when there is an attempt to combine two instances of a non-combinable delegate type unless one of the operands is a null reference (Nothing in Visual Basic). This class cannot be inherited.

NetPipeStyleUriParser

A parser based on the NetPipe scheme for the "Indigo" system.

NetTcpStyleUriParser

A parser based on the NetTcp scheme for the "Indigo" system.

NewsStyleUriParser

A customizable parser based on the news scheme using the Network News Transfer Protocol (NNTP).

NonSerializedAttribute

Indicates that a field of a serializable class should not be serialized. This class cannot be inherited.

NotFiniteNumberException

The exception that is thrown when a floating-point value is positive infinity, negative infinity, or Not-a-Number (NaN).

NotImplementedException

The exception that is thrown when a requested method or operation is not implemented.

NotSupportedException

The exception that is thrown when an invoked method is not supported, or when there is an attempt to read, seek, or write to a stream that does not support the invoked functionality.

Nullable

Supports a value type that can be assigned a null reference (Nothing in Visual Basic) like a reference type. This class cannot be inherited.

NullReferenceException

The exception that is thrown when there is an attempt to dereference a null object reference.

Object

Supports all classes in the .NET Framework class hierarchy and provides low-level services to derived classes. This is the ultimate base class of all classes in the .NET Framework; it is the root of the type hierarchy.

ObjectDisposedException

The exception that is thrown when an operation is performed on a disposed object.

ObsoleteAttribute

Marks the program elements that are no longer in use. This class cannot be inherited.

OperatingSystem

Represents information about an operating system, such as the version and platform identifier. This class cannot be inherited.

OperationCanceledException

The exception that is thrown in a thread upon cancellation of an operation that the thread was executing.

OutOfMemoryException

The exception that is thrown when there is not enough memory to continue the execution of a program.

OverflowException

The exception that is thrown when an arithmetic, casting, or conversion operation in a checked context results in an overflow.

ParamArrayAttribute

Indicates that the method will allow a variable number of arguments in its invocation. This class cannot be inherited.

PlatformNotSupportedException

The exception that is thrown when a feature does not run on a particular platform.

Random

Represents a pseudo-random number generator, a device that produces a sequence of numbers that meet certain statistical requirements for randomness.

RankException

The exception that is thrown when an array with the wrong number of dimensions is passed to a method.

ResolveEventArgs

Provides data for the TypeResolve, ResourceResolve, and AssemblyResolve events.

SerializableAttribute

Indicates that a class can be serialized. This class cannot be inherited.

StackOverflowException

The exception that is thrown when the execution stack overflows by having too many pending method calls. This class cannot be inherited.

STAThreadAttribute

Indicates that the COM threading model for an application is single-threaded apartment (STA).

String

Represents text as a series of Unicode characters.

StringComparer

Represents a string comparison operation that uses specific case and culture-based or ordinal comparison rules.

SystemException

Defines the base class for predefined exceptions in the System namespace.

ThreadStaticAttribute

Indicates that the value of a static field is unique for each thread.

TimeoutException

The exception that is thrown when the time allotted for a process or operation has expired.

TimeZone

Represents a time zone.

Type

Represents type declarations: class types, interface types, array types, value types, enumeration types, type parameters, generic type definitions, and open or closed constructed generic types.

TypeInitializationException

The exception that is thrown as a wrapper around the exception thrown by the class initializer. This class cannot be inherited.

TypeLoadException

The exception that is thrown when type-loading failures occur.

TypeUnloadedException

The exception that is thrown when there is an attempt to access an unloaded class.

UnauthorizedAccessException

The exception that is thrown when the operating system denies access because of an I/O error or a specific type of security error.

UnhandledExceptionEventArgs

Provides data for the event that is raised when there is an exception that is not handled by the application domain.

Uri

Provides an object representation of a uniform resource identifier (URI) and easy access to the parts of the URI.

UriBuilder

Provides a custom constructor for uniform resource identifiers (URIs) and modifies URIs for the Uri class.

UriFormatException

The exception that is thrown when an invalid Uniform Resource Identifier (URI) is detected.

UriParser

Parses a new URI scheme. This is an abstract class.

UriTypeConverter

Converts a String type to a Uri type, and vice versa.

ValueType

Provides the base class for value types.

Version

Represents the version number for a common language runtime assembly. This class cannot be inherited.

WeakReference

Represents a weak reference, which references an object while still allowing that object to be garbage collected.

 

Table 1

 

 

Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7 | Part 8

 


 

< .Net Framework Class Library 2 | Main | .Net Framework Class Library 4 >