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 NamespacesThroughout 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.
The C# compiler does not require using
declarations in a source-code file if the fully qualified class name is specified every time a class name is used. Most programmers prefer the more concise programming style enabled by using
declarations.
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.
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.5, 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.) |
|
Contain the classes of the Windows Presentation Foundation for GUIs, 2-D and 3-D graphics, multimedia and animation. (See the online WPF chapters.) |
System.Linq |
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 22, 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. (See the online ASP.NET Web App Development chapter.) |
System.Xml |
Contains the classes for creating and manipulating XML data. Data can be read from or written to XML files. (See the online XML and LINQ to XML chapter.) |
System.Xml.Linq |
Contains the classes that support Language Integrated Query (LINQ) for XML documents. (See the online XML and LINQ to XML chapter, and several other chapters throughout the book.) |
|
Contain the classes that define data structures for maintaining collections of data. (See Chapter 21, Generic Collections; Functional Programming with LINQ/PLINQ.) |
System.Text |
Contains classes that enable programs to manipulate characters and string s. (See Chapter 16, Strings and Characters: A Deeper Look.) |
You can locate additional information about a .NET class’s methods in the .NET Framework Class Library reference
https://msdn.microsoft.com/library/mt472912
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.
The online .NET Framework documentation is easy to search and provides many details about each class. As you learn each class in this book, you should review the class in the online documentation for additional information.