- 7.1 Introduction
- 7.2 Packaging Code in C#
- 7.3 static Methods, static Variables and Class Math
- 7.4 Methods with Multiple Parameters
- 7.5 Notes on Using Methods
- 7.6 Argument Promotion and Casting
- 7.7 The .NET Framework Class Library
- 7.8 Case Study: Random-Number Generation
- 7.9 Case Study: A Game of Chance; Introducing Enumerations
- 7.10 Scope of Declarations
- 7.11 Method-Call Stack and Activation Records
- 7.12 Method Overloading
- 7.13 Optional Parameters
- 7.14 Named Parameters
- 7.15 C# 6 Expression-Bodied Methods and Properties
- 7.16 Recursion
- 7.17 Value Types vs. Reference Types
- 7.18 Passing Arguments By Value and By Reference
- 7.19 Wrap-Up
7.7 The .NET Framework Class Library
Many predefined classes are grouped into categories of related classes called namespaces. Together, these namespaces are referred to as the .NET Framework Class Library.
using Directives and Namespaces
Throughout the text, using directives allow us to use library classes from the Framework Class Library without specifying their namespace names. For example, an app would include the declaration
using System;
in order to use the class names from the System namespace without fully qualifying their names. This allows you to use the unqualified name Console, rather than the fully qualified name System.Console, in your code.
You might have noticed in each project containing multiple classes that in each class’s source-code file we did not need additional using directives to use the other classes in the project. There’s a special relationship between classes in a project—by default, such classes are in the same namespace and can be used by other classes in the project. Thus, a using declaration is not required when one class in a project uses another in the same project—such as when class AccountTest used class Account in Chapter 4’s examples. Also, any classes that are not explicitly placed in a namespace are implicitly placed in the so-called global namespace.
.NET Namespaces
A strength of C# is the large number of classes in the namespaces of the .NET Framework Class Library. Some key Framework Class Library namespaces are described in Fig. 7.4, which represents only a small portion of the reusable classes in the .NET Framework Class Library.
Namespace |
Description |
System.Windows.Forms |
Contains the classes required to create and manipulate GUIs. (Various classes in this namespace are discussed in Chapter 14, Graphical User Interfaces with Windows Forms: Part 1, and Chapter 15, Graphical User Interfaces with Windows Forms: Part 2.) |
System.Windows.Controls System.Windows.Input System.Windows.Media System.Windows.Shapes System.Linq |
Contain the classes of the Windows Presentation Foundation for GUIs, 2-D and 3-D graphics, multimedia and animation. Contains the classes that support Language Integrated Query (LINQ). (See Chapter 9, Introduction to LINQ and the List Collection, and several other chapters throughout the book.) |
System.Data.Entity |
Contains the classes for manipulating data in databases (i.e., organized collections of data), including support for LINQ to Entities. (See Chapter 20, Databases and LINQ.) |
System.IO |
Contains the classes that enable programs to input and output data. (See Chapter 17, Files and Streams.) |
System.Web |
Contains the classes used for creating and maintaining web apps, which are accessible over the Internet. |
System.Xml |
Contains the classes for creating and manipulating XML data. Data can be read from or written to XML files. |
System.Xml.Linq |
Contains the classes that support Language Integrated Query (LINQ) for XML documents. (See Chapter 21, Asynchronous Programming with async and await.) |
System.Collections System.Collections.Generic |
Contain the classes that define data structures for maintaining collections of data. (See Chapter 19, Generic Collections; Functional Programming with LINQ/PLINQ.) |
System.Text |
Contains classes that enable programs to manipulate characters and strings. (See Chapter 16, Strings and Characters: A Deeper Look.) |
Fig. 7.4 | .NET Framework Class Library namespaces (a subset).
Locating Additional Information About a .NET Class’s Methods
You can locate additional information about a .NET class’s methods in the .NET Framework Class Library reference
When you visit this site, you’ll see an alphabetical listing of all the namespaces in the Framework Class Library. Locate the namespace and click its link to see an alphabetical listing of all its classes, with a brief description of each. Click a class’s link to see a more complete description of the class. Click the Methods link in the left-hand column to see a listing of the class’s methods.