O'Reilly logo

Programming C# 4.0 by Jesse Liberty, Matthew Adams, Ian Griffiths

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Namespaces and Types

The .NET Framework class library is big. To make it easier to find your way around the many services it offers, the library is split into namespaces. For example, the System.IO namespace offers I/O (Input/Output) services such as working with files on disk, while System.Data.SqlClient is for connecting to a SQL Server database.

A namespace contains types. A type typically represents either a kind of information or a kind of object. For example, there are types that provide the core forms of information used in all programs, such as System.String which represents text, or the various numeric types such as System.Double or System.Int32. Some types are more complex—for example, the System.Net.HttpWebRequest class represents an HTTP request to be sent to a web server. A few types do not represent any particular thing, but simply offer a set of services, such as the System.Math class, which provides mathematical functions such as Sin and Log, and constants such as π or the base of natural logarithms, e. (We will explore the nature of types, objects, and values in much more detail in the next chapter.)

All types in the .NET Framework class library belong to a namespace. The purpose of a using directive is to save you from typing the namespace every single time you need to use a class. For example, in a file that has a using System; directive you can just write Math.PI to get the value of π, instead of using the full name, System.Math.PI. You’re not required to write ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required