Appd

  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Appd as PDF for free.

More details

  • Words: 3,004
  • Pages: 13
Color profile: Generic CMYK printer profile Composite Default screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter D All-In-One

APPENDIX

The .NET Class Library The .NET Framework includes an extensive collection of prebuilt class files. These have been grouped together in meaningful namespaces and published to the .NET Class Library. It would fill the entire book if we were to cover every class and namespace here. However, that is not our purpose. What we will attempt to do is document some of the more common and possibly more useful classes in the library. Keep in mind that any class you select from the class library can be used in any of the .NET programming languages, so, in effect, this appendix is pertinent to all of the languages included in .NET, such as Visual Basic .NET, JScript .NET, and so on.

Accessing Classes from the .NET Class Library The .NET Class Library is broken down into namespaces which, as we have seen, are a convenient way to group together classes with a common or related background. Figure D-1 illustrates a very small piece of the .NET Class Library. When you look at this diagram,

Figure D-1

A small subset of the .NET Class Library

1 P:\010Comp\All-in-1\443-6\appd.vp Monday, August 26, 2002 11:57:40 AM

D

Color profile: Generic CMYK printer profile Composite Default screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter D All-In-One

MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide

2 keep in mind that we have only shown 6 of the approximately 84 namespaces, and under each namespace only two of hundreds of the underlying classes. If this has given you a sense of the magnitude of this library, remember that you can add to it as well. We are only looking at Microsoft’s structure in these instances—third-party namespaces will expand the library even further. Every namespace that you explore within the class library contains classes, structures, enums, delegates, and interfaces (not necessary all of them) that you can use in your programs. As discussed before, to use a namespace, code a line like the following at the beginning of your program: using System;

This code tells the compiler that you may be using one or more of the different types in the System namespace. There are many ways to access the documentation for .NET Library types. We will talk about two of the ways. First, within the Visual Studio .NET development environment is a large documentation and help subsystem. Figure D-2 shows the root of the .NET Class Library help structure. The best way to find it is by typing Class Library in the Look For

Figure D-2

P:\010Comp\All-in-1\443-6\appd.vp Monday, August 26, 2002 11:57:41 AM

Documentation for the .NET Class Library

Color profile: Generic CMYK printer profile Composite Default screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter D All-In-One

Appendix D: The .NET Class Library

3 field (a search tool). When you do this, you will see the introduction page, and you can begin locating valuable information by clicking on the Class Library hyperlink. That link will direct you to a page that has links to every namespace in the .NET library, as shown in Figure D-3. TIP You can add the web page to your list of favorites by selecting View | Other Windows and Favorites from the menus. If you are anything like us, you will find this page extremely helpful as you become familiar with the classes available to you. By selecting one of the namespaces shown in Figure D-3, you will find that you are able to see all of the classes within that namespace. There is another way to find help on the .NET Class Library, and that is by using Microsoft’s MSDN web site at http://msdn.microsoft.com. Currently, the page that you saw in Figure D-2 is also on Microsoft’s site (see Figure D-4). Whichever method you choose when accessing the documentation, you will find that Microsoft has spent a fair bit of time in making sure that the information is available to you and is easily readable.

PART VII

Figure D-3

The .NET Class Library namespaces

P:\010Comp\All-in-1\443-6\appd.vp Monday, August 26, 2002 11:57:41 AM

Color profile: Generic CMYK printer profile Composite Default screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter D All-In-One

MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide

4

Figure D-4

The .NET Class Library documentation on the Internet

The System Namespace Microsoft has grouped together a collection of classes that will help you with common tasks. Table D-1 gives you an example of some of the classes that you might find in the System namespace. Remember that this is just a short list of common classes available in the System namespace. Take some time to become familiar with the other classes in the library.

The Math Class There are a lot of classes to choose from, but in order to illustrate how to use the class library, we have selected the Math class as our demonstration class. Figure D-5 shows the page you will receive if you choose the System link from Figure D-3 and then click the Math link. There are a number of things to observe in Figure D-5. Notice that the inheritance hierarchy is in the top left corner—the Math class inherits directly from System.Object. In the large, gray-shaded area you can see the definition code for the class—public sealed class Math. This means that you cannot create any children of the Math class.

P:\010Comp\All-in-1\443-6\appd.vp Monday, August 26, 2002 11:57:41 AM

Color profile: Generic CMYK printer profile Composite Default screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter D All-In-One

Appendix D: The .NET Class Library

5 Class Name

Purpose

ApplicationException Array Console

A parent class for non-terminating program errors. Methods for creating, searching, and sorting arrays. Standard input, output, and error streams. These are used for console applications. A class for controlling the system garbage collector. Methods for common mathematical functions. See the “The Math Class” section that follows for more details. The parent class of every class. A class that provides information about the operating system—version and the like. An immutable set of characters. The base class for predefined exceptions. A structure that represents 32-bit unsigned integers.

GC Math Object OperatingSystem String SystemException UInt32 Table D-1

A Short List of the Types of Classes in the System Namespace

PART VII

Figure D-5

The Math class documentation

P:\010Comp\All-in-1\443-6\appd.vp Monday, August 26, 2002 11:57:42 AM

Color profile: Generic CMYK printer profile Composite Default screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter D All-In-One

MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide

6 This summary page also shows you how safe the code is to use in multithreaded operations. Notice, as well, that the platforms are listed on this page, along with the assembly in which the class is found (in this case Mscorlib.dll). If you are interested in checking out the properties and methods that are available for use in this class, click the Math Members link. You will see a screen that looks like the one in Figure D-6. There are two fields, E and PI, that are listed, along with their purpose. As you can see from the list, there are many public methods in the Math class. We will select one, the Round() method, in order to dig deeper into this documentation. The Round() method is used to return the integer nearest to the number given, following the rules of rounding. For example, the following code segment returns 12. using System; class Rounding { public static void Main() { Console.WriteLine (Math.Round(12.42)); } }

Figure D-6

P:\010Comp\All-in-1\443-6\appd.vp Monday, August 26, 2002 11:57:42 AM

Math members

Color profile: Generic CMYK printer profile Composite Default screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter D All-In-One

Appendix D: The .NET Class Library

7 In order to select the documentation for the Round() method, simply click on the method in the window shown in Figure D-6, and you will see the screen in Figure D-7. This method is overloaded four times in order to give you an opportunity to pass it different sets of parameters. In our previous example, we simply sent the method a double value (12.42). However, you could send a decimal and an int, as well as a double and an int. This again demonstrates the power of overloading methods—you don’t have to remember four different method names. Notice the signature of all the methods. They are all static methods. This means that you do not need an instance of the class in order to call the methods. As a matter of fact, if you examine the code from our example, you will notice that we simply called the method directly from the class name itself: Console.WriteLine (Math.Round(12.42));

Most of the utility methods in the System class will operate in a similar fashion. If you wish to dig deeper into the documentation, you can select any of the links for the overloaded methods. We chose the first one to demonstrate: public static decimal Round(decimal);

PART VII

Figure D-7

The Round( ) method from the Math class

P:\010Comp\All-in-1\443-6\appd.vp Monday, August 26, 2002 11:57:42 AM

Color profile: Generic CMYK printer profile Composite Default screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter D All-In-One

MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide

8 As Figure D-8 shows, by selecting the link, you receive valuable information detailing the method. Even though we have chosen to look at a relatively easy concept, rounding, you can imagine that if you needed to find out about a method you knew nothing about, the documentation presented here would be worth its weight in gold.

A Final Note on the System Namespace Microsoft has attempted to alleviate some of the confusion that can arise when there are so many different namespaces and classes from which to choose. By using the System namespace and then further subdividing it, you really have one focused area in which to start your search. You will find that there are a few other top-level namespaces, such as Microsoft.Csharp, Microsoft.Jscript, Microsoft.VisualBasic, and so on, that are used to describe classes pertinent to the individual languages. However, you will probably spend most of your time in the System namespace. Although this is not specific to the System namespace, there is another area of the documentation that may be of interest to you. It is possible to view the namespace hierarchy in order to see which classes are base classes and which are derived classes. Figure D-9 illustrates the System namespace inheritance scheme. You will find a link on each of the namespace home pages that will take you to <> hierarchy.

Figure D-8

P:\010Comp\All-in-1\443-6\appd.vp Monday, August 26, 2002 11:57:42 AM

Digging deeper in the Math documentation

Color profile: Generic CMYK printer profile Composite Default screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter D All-In-One

Appendix D: The .NET Class Library

9

Figure D-9

The System namespace inheritance hierarchy

Useful System Namespaces We will now take a brief look at some of the namespaces that might be pertinent to you on the Microsoft exams, in particular, System.Data, System.Web.UI, and System.Windows.Forms. You saw System.Data in Chapter 10, and the other two were discussed in Parts III and IV on Web and Windows development.

System.Data Namespace

P:\010Comp\All-in-1\443-6\appd.vp Monday, August 26, 2002 11:57:42 AM

PART VII

You will find in the System.Data namespace a lot of classes that make up part of the ADO.NET structure. This allows you to manipulate data from many different sources. ADO follows a concept of universal data access and provides tools to access, update, and connect to data in any location. For more information on ADO.NET, please review Chapter 10 on basic data access. Table D-2 lists some of the classes found in this namespace. There are many classes, interfaces, delegates, and enumerations available within the System.Data namespace. For example, in the following list, you will see the inheritance structure of the classes in the System.Data namespace. You can use this as a reference

Color profile: Generic CMYK printer profile Composite Default screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter D All-In-One

MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide

10 Class

Purpose

Constraint DataColumn DataException DataRelation DataRow DataSet DataTable

Simulates a constraint on one or more DataColumn objects. Represents the field level from a table. Represents an exception that is thrown from ADO.NET components. Represents the relationship between two DataTable objects. Same as DataColumn, except it represents a row of data. Represents the powerful, internal cache of data returned. Represents one table of in-memory data.

Table D-2

Sample classes from the System.Data namespace

to the classes that are available in the namespace. Although this is a long list, for the purposes of the three Microsoft exams, you should become familiar with this namespace. System.Object System.Attribute System.ComponentModel.DescriptionAttribute System.Data.DataSysDescriptionAttribute System.Collections.Hashtable System.Data.PropertyCollection System.ComponentModel.MarshalByValueComponent System.Data.DataColumn System.Data.DataSet ---- System.ComponentModel.IListSource, System.ComponentModel.ISupportInitialize, System.Runtime.Serialization.ISerializable System.Data.DataTable ---- System.ComponentModel.IListSource, System.ComponentModel.ISupportInitialize, System.Runtime.Serialization.ISerializable System.Data.DataView ---- System.ComponentModel.IBindingList, System.Collections.IList, System.Collections.ICollection, System.Collections.IEnumerable, System.ComponentModel.ITypedList, System.ComponentModel.ISupportInitialize System.Data.DataViewManager ---- System.ComponentModel.IBindingList, System.Collections.IList, System.Collections.ICollection, System.Collections.IEnumerable, System.ComponentModel.ITypedList System.Data.Constraint System.Data.ForeignKeyConstraint System.Data.UniqueConstraint System.Data.DataRelation System.Data.DataRow System.Data.DataRowView ---- System.ComponentModel.ICustomTypeDescriptor, System.ComponentModel.IEditableObject, System.ComponentModel.IDataErrorInfo System.Data.DataViewSetting

P:\010Comp\All-in-1\443-6\appd.vp Monday, August 26, 2002 11:57:43 AM

Color profile: Generic CMYK printer profile Composite Default screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter D All-In-One

Appendix D: The .NET Class Library

11

P:\010Comp\All-in-1\443-6\appd.vp Monday, August 26, 2002 11:57:43 AM

PART VII

System.Data.DataViewSettingCollection ---- System.Collections.ICollection, System.Collections.IEnumerable System.Data.InternalDataCollectionBase System.Data.ConstraintCollection System.Data.DataColumnCollection System.Data.DataRelationCollection System.Data.DataRowCollection System.Data.DataTableCollection System.Data.TypedDataSetGenerator System.Delegate System.MulticastDelegate System.Data.DataColumnChangeEventHandler System.Data.DataRowChangeEventHandler System.Data.FillErrorEventHandler System.Data.MergeFailedEventHandler System.Data.StateChangeEventHandler System.EventArgs System.Data.DataColumnChangeEventArgs System.Data.DataRowChangeEventArgs System.Data.FillErrorEventArgs System.Data.MergeFailedEventArgs System.Data.StateChangeEventArgs System.Exception System.SystemException System.Data.DataException System.Data.ConstraintException System.Data.DeletedRowInaccessibleException System.Data.DuplicateNameException System.Data.InRowChangingEventException System.Data.InvalidConstraintException System.Data.InvalidExpressionException System.Data.EvaluateException System.Data.SyntaxErrorException System.Data.MissingPrimaryKeyException System.Data.NoNullAllowedException System.Data.ReadOnlyException System.Data.RowNotInTableException System.Data.StrongTypingException System.Data.TypedDataSetGeneratorException System.Data.VersionNotFoundException System.Data.DBConcurrencyException System.ValueType System.Enum System.Data.AcceptRejectRule System.Data.CommandBehavior System.Data.CommandType System.Data.ConnectionState System.Data.DataRowAction System.Data.DataRowState System.Data.DataRowVersion System.Data.DataViewRowState System.Data.DbType System.Data.IsolationLevel System.Data.MappingType System.Data.MissingMappingAction System.Data.MissingSchemaAction System.Data.ParameterDirection System.Data.PropertyAttributes

Color profile: Generic CMYK printer profile Composite Default screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter D All-In-One

MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide

12 System.Data.Rule System.Data.SchemaType System.Data.SqlDbType System.Data.StatementType System.Data.UpdateRowSource System.Data.UpdateStatus System.Data.XmlReadMode System.Data.XmlWriteMode

TIP You would be wise to investigate this namespace thoroughly before writing the Microsoft exams. Although you will find the testing more specific to data access within the Web or Windows Forms, you will still need to have a good understanding of ADO.NET, the architecture for which the System.Data namespace was built.

System.Web.UI Namespace Just as the classes for ADO.NET were encapsulated inside of the System.Data namespace, you will find the classes and interfaces for ASP.NET server controls and pages inside the System.Web.UI namespace. These classes will allow you to create the user interface components for your web applications. You will discover classes that provide server controls, user controls, data binding, web page state management, and a lot more here. Table D-3 lists a few of the classes to be found in System.Web.UI. The use of this namespace is discussed in an entire part of this book, Part III. You will need to understand it for the web application exam.

The System.Windows.Forms Namespace The System.Windows.Forms namespace is a very large namespace that is used for creating Windows-based applications. In order to take advantage of the power of the Class

Purpose

Control

Contains properties, methods, and events that are shared by all ASP.NET server controls. Creates data-binding expressions at design time within Visual Studio .NET. Writes a sequential series of HTML-specific characters and text on a Web Forms page. Represents an .aspx file. Represents the state of server controls in terms of their view state. Represents the .ascx file when it is called from an .aspx file.

DataBinding HtmlTextWriter Page StateBag UserControl Table D-3

P:\010Comp\All-in-1\443-6\appd.vp Monday, August 26, 2002 11:57:43 AM

Some of the Classes Within the System.Web.UI Namespace

Color profile: Generic CMYK printer profile Composite Default screen / MCAD/MCSD Visual C# .NET Certification All-in-One Exam Guide / Rempel & Lind / 222443-6 / Chapter D All-In-One

Appendix D: The .NET Class Library

13 Windows operating system, many classes have been prebuilt to represent components in the Windows interface. You will find the following types of classes in this namespace: • Controls You will find text boxes, combo boxes, labels, lists, buttons, and the like in this grouping. • Control, User Control, and Form Control is base class for all the controls on a Windows form. The form allows you to create dialog boxes, windows, and so on, and the user control is there so that you can create custom controls that are made up of other controls. • Common Dialog Boxes If you want to represent the common file-open, file-print, font, and other dialog boxes, you will find a lot of useful classes in this section of the namespace. • Components

You will find menus, help, tool tips, and the like here.

As we mentioned, this is a very large namespace, and as such, is better viewed within the documentation. Part IV of this book explores several of the classes found in the System.Windows.Forms namespace. As with System.Web.UI, you will need to know these classes for the exam, so we have devoted a full part of the book to them.

Summary This has been a brief introduction to the .NET Class Library. Hopefully you now have an appreciation for the amount of work that has been done by the developers of the library, to help you spend more time on your business problems. We recommend that you dig around the documentation a bit in order to become more familiar with the classes in the different namespaces.

PART VII

P:\010Comp\All-in-1\443-6\appd.vp Monday, August 26, 2002 11:57:43 AM

Related Documents

Appd
December 2019 22
Appd
November 2019 9
Mkg Spc Appd
November 2019 9