Web hosting bandwidth - Chapter 6 Methods 195 int result = Square(
Chapter 6 Methods 195 int result = Square( ( int ) y ); This statement explicitly casts (converts) a copy of the value of y to an integer for use in method Square. Thus, if y s value is 4.5, method Square returns 16, not 20.25. Common Programming Error 6.11 When performing a narrowing conversion (e.g., double to int), converting a primitive- data-type value to another primitive data type may change the value. Also, converting any integral value to a floating-point value and back to an integral value may introduce rounding errors into the result. 6.7 C# Namespaces As we have seen, C# contains many predefined classes that are grouped into namespaces. Collectively we refer to this preexisting code as the Framework Class Library. The actual code for the classes is located in .dll files called assemblies. Throughout the text, using statements specify the namespaces we use in each program. For example, a program includes the statement using System; to tell the compiler that we are using the System namespace. This using statement allows us to write Console.WriteLine rather than System.Console.WriteLine throughout the program. To use a class in a particular namespace, we must add a reference to the appropriate assembly (demonstrated in Section 3.2). Assembly references for namespace System are added automatically other assemblies must be added explicitly. We exercise a large number of the FCL classes in this book. Figure 6.6 lists a subset of the many namespaces in the FCL and provides a brief description of each. We use classes from these namespaces and others throughout the book. This table introduces readers to the variety of reusable components in the FCL. When learning C#, spend time reading the descriptions of the classes in the documentation. Namespace Description System Contains essential classes and data types (such as int, double, char, etc.). Implicitly referenced by all C# programs. System.Data Contains classes that form ADO .NET, used for database access and manipulation. System.Drawing Contains classes used for drawing and graphics. System.IO Contains classes for the input and output of data, such as with files. System.Threading Contains classes for multithreading, used to run multiple parts of a program simultaneously. System.Windows.Forms Contains classes used to create graphical user interfaces. System.Xml Contains classes used to process XML data. Fig. 6.6 Namespaces in the Framework Class Library.
Visit our web design programs services for an affordable and reliable webhost to suit all your needs.