14
Advance Your Reputation With Courseware That Client’s Respect! PROFESSIONALSERIES Courseware From The Experts Complete C#.NET 2005 Courseware Course Manual(s) Lab Manual Lab Solutions (digital) Slides APRESS Publication* Overview Authored and field tested by Andrew Troelsen, Best-Selling C#.NET author, this five day instructor led course delivers comprehensive coverage of C#.NET and the CLR. Target Audience Engineers, Developers, Programmers, and Software Development Professionals. Learning Objectives The architecture of Microsoft .NET 2.0 How to develop several differnet types of .NET applications (Console, Windows, web, web services and class libraries) The three pillars of OOP (Object Oriented Programming) How to efficiently retrieve and maniulalte data from multiple data sources The Visual Studio 2005 editor and all of its advantages How to work with .NET assemblies (EXEs and DLLs) Reading, writing and serializing data to streams and files Late binding with Reflection Length: 5 days Price: $150 Per Student ( $30 Per Day — 10 Unit Minimum Required ) A ORDER Abstract & Content Overview A

Complete C#.NET 2005 Courseware

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Advance Your Reputation With Courseware That Client’s Respect!

PROFESSIONALSERIESCourseware From The Experts

Complete C#.NET 2005 Courseware

Course Manual(s)

Lab Manual

Lab Solutions (digital)

Slides

APRESS Publication*

Overview

Authored and field tested by Andrew Troelsen, Best-Selling C#.NET author, this five day instructor led course delivers comprehensive coverage of C#.NET and the CLR.

Target Audience

Engineers, Developers, Programmers, and Software Development Professionals.

Learning Objectives

• The architecture of Microsoft .NET 2.0• How to develop several differnet types of .NET applications (Console, Windows, web, web services and class libraries)• The three pillars of OOP (Object Oriented Programming)• How to efficiently retrieve and maniulalte data from multiple data sources• The Visual Studio 2005 editor and all of its advantages• How to work with .NET assemblies (EXEs and DLLs)• Reading, writing and serializing data to streams and files• Late binding with Reflection

Length: 5 days Price: $150 Per Student

( $30 Per Day — 10 Unit Minimum Required )

A

ORDER Abstract & Content Overview

A

ORDER

Course Abstract: Complete C#.NET 2005 Courseware

The .NET platform brings a streamlined elegance to Windows and Web development, and C# is the language designed specifically for the .NET development. Intertech Training's Complete C# 2005 provides in-depth coverage of both the language(C# 2005) and the platform (.NET 2.0). The class begins with an overview of the core atoms of the .NET universe; CLR, CTS, CLS, CIL and the assembly / namespace / type distinction. You will then learn the details of the C# language including several new features such as nullable data types, partial classes and generics.

The focus of the class then shifts to various technologies provided by the .NET 2.0 platform, including file I/O and object serialization, reflection services, Windows Forms 2.0, ADO.NET 2.0 and an introduction to ASP.NET 2.0 Web applications and XML Web services. Throughout the week, attendees will also be exposed to numerous aspects of the Visual Studio 2005 IDE and make use of various integrated development tools (refactoring support, code snippets, visual type designers, etc). The class materials also include numerous appendixes which will be covered if time permits (or per client request).

Throughout the course you will complete several practical hands-on exercises that demonstrate how to apply .NET technologies in the real world. This course uses Visual Studio 2005 and .NET 2.0

Contents

Table of Contents Courseware Excerpt

Intertech 1020 Discovery Road, Suite 145 St. Paul, MN 55121 USA Tel: 651 994 8558 Fax: 651 994 9119 Toll Free: +800 866 9884 www.Intertechcourseware.com

PROFESSIONALSERIESCourseware From The Experts

Advance Your Reputation With Courseware That Client’s Respect!

Option Customize Manual With Your Logo! ( $100 per Order — Visit www.intertechcourseware.com For Details )

Course Manual

• Full content—not just a copy of instructor’s slides

• Follows slides—facilitating lecture and note taking

• Indexed—provides a great reference after class

• Field-tested with America’s top companies

• Created by published, proven authors

Lab Manual

• Lab setup guide for easy software/tools installation

• Matches and reinforces learning concepts

• Defines steps for students to build their own solutions

Slides

• Follows Course Manual

• .PDF format for portability across platforms

Lab Solutions (Digital)

• Available from digital download site

• Full solutions for each lab

PLUS … Instructor Receives APRESS Publication

• FREE Apress book that corresponds with courseware

• From the courseware author (in most cases)

• Serves as in-depth reference for instructor

A

ORDER Overview Courseware Excerpt

Intertech 1020 Discovery Road, Suite 145 St. Paul, MN 55121 USA Tel: 651 994 8558 Fax: 651 994 9119 Toll Free: +800 866 9884 www.Intertechcourseware.com

A

A

PROFESSIONALSERIESCourseware From The Experts

Complete C#.NET 2005 Courseware

Table of Contents

© Intertech 2008— All Rights Reserved

Chapter 1...................................................................................................................... 1-1

The Philosophy of .NET ............................................................................................... 1-1

Overview .......................................................................................................... 1-2

Remembering the World of COM ........................................................................ 1-3

COM Problems and .NET Solutions ..................................................................... 1-4

The .NET Universe ........................................................................................... 1-10

The Role of the Common Type System (CTS)....................................................... 1-12

The Role of the Common Language Specification (CLS) ...................................... 1-14

The Role of the Common Language Runtime (CLR) .......................................... 1-16

The Role of .NET Namespaces .......................................................................... 1-18

The Role of Common Intermediate Language ..................................................... 1-22

The Role of Assemblies, Manifests and ILDasm ................................................... 1-23

Paths to Managed Code: A Survey of .NET Languages ........................................ 1-29

The CLI: The Basis of .NET’s Platform Independence ........................................... 1-32

Building C# Applications Using csc.exe ............................................................. 1-35

Chapter Summary ........................................................................................... 1-39

Chapter 2...................................................................................................................... 2-1

C# Language Fundamentals ......................................................................................... 2-1

Chapter Overview ............................................................................................. 2-2

The Anatomy of a Basic C# Application ............................................................... 2-3

Defining a Custom C# Class Type ...................................................................... 2-6

Partial Class Definitions...................................................................................... 2-8

Field Initialization .............................................................................................. 2-9

Constructors and Finalizers............................................................................... 2-10

C# Decision Constructs ................................................................................... 2-13

Looping Constructs .......................................................................................... 2-18

Parameter Modifiers ........................................................................................ 2-19

Method Overloading ....................................................................................... 2-23

Exception Handling.......................................................................................... 2-25

Building Custom Exceptions .............................................................................. 2-27

Chapter Summary ........................................................................................... 2-31

Chapter 3...................................................................................................................... 3-1

Object Oriented Programming with C# ......................................................................... 3-1

Chapter Overview ............................................................................................. 3-2

Encapsulation and Class Development ................................................................ 3-3

Defining Static Members .................................................................................... 3-8

Static Class Definitions ..................................................................................... 3-14

Constant and the readonly Modifier .................................................................. 3-16

The Role of the ‘this’ Keyword ........................................................................... 3-19

Implementation inheritance .............................................................................. 3-22

Implementation Inheritance: A Complete Example .............................................. 3-24

Implementing the Employee Base Class ............................................................. 3-25

Implementing the WageEmployee Class ............................................................ 3-27

Implementing the SalesEmployee Class ............................................................. 3-29

Implementing the Manager class....................................................................... 3-32

Abstract Methods and Classes .......................................................................... 3-33

Interfaces and Polymorphism ............................................................................ 3-36

Explicit Interface Implementation ....................................................................... 3-40

Interfaces versus Abstract Classes ...................................................................... 3-44

Multiple Interface Inheritance ............................................................................ 3-47

Type Casting ................................................................................................... 3-48

Inheritance and Composition ............................................................................ 3-51

Defining Nested Types ..................................................................................... 3-53

Overloading Operators .................................................................................... 3-56

Overloading the Comparison Operators ............................................................ 3-59

Chapter Summary ........................................................................................... 3-61

Chapter 4...................................................................................................................... 4-1

.NET Programming Fundamentals................................................................................ 4-1

Chapter Overview ............................................................................................. 4-2

Value Types and Reference Types ........................................................................ 4-3

The Role of System.Object .................................................................................. 4-8

Overriding Various Members of System.Object ................................................... 4-10

The System Data Types .................................................................................... 4-16

Understanding Nullable Data Types .................................................................. 4-19

.NET String Formatting Syntax ........................................................................... 4-24

String Manipulation ......................................................................................... 4-28

Array Manipulation .......................................................................................... 4-32

Defining Enumerations ..................................................................................... 4-35

Defining Custom Namespaces .......................................................................... 4-39

Understanding Delegates ................................................................................. 4-45

Using Events ................................................................................................... 4-51

Delegate Covariance and Contravariance.......................................................... 4-53

Understanding Anonymous Methods ................................................................. 4-56

Understanding Method Group Conversion ......................................................... 4-58

Chapter Summary ........................................................................................... 4-61

Chapter 5...................................................................................................................... 5-1

Understanding Generics ............................................................................................... 5-1

Chapter Overview ............................................................................................. 5-2

Understanding the Role of Generics .................................................................... 5-3

Issues with Boxing and Unboxing ........................................................................ 5-4

Issues with Custom Collections ............................................................................ 5-6

Consuming Generic Types................................................................................ 5-10

Creating Custom Generic Methods ................................................................... 5-13

Building Custom Generic Types ........................................................................ 5-15

Constraining Type Parameters .......................................................................... 5-18

Chapter Summary ........................................................................................... 5-20

Chapter 6...................................................................................................................... 6-1

Understanding .NET Assemblies .................................................................................. 6-1

Chapter Overview ............................................................................................. 6-2

An Overview of .NET Assemblies ......................................................................... 6-3

Building a Single File Assembly ........................................................................... 6-4

Building a Client Application............................................................................... 6-7

Cross-Language Inheritance ............................................................................... 6-9

Exploring the Manifest ...................................................................................... 6-10

Understanding Private Assemblies ..................................................................... 6-12

Authoring Application Configuration Files .......................................................... 6-14

Understanding Shared Assemblies .................................................................... 6-16

Creating a Strongly Named Assembly ................................................................ 6-17

Installing a Strongly Named Assembly to the GAC .............................................. 6-21

Versioning Policies and Shared Assemblies ......................................................... 6-22

Redirecting assembly requests ........................................................................... 6-24

Understanding Publisher Policy ......................................................................... 6-25

Using the <codeBase> Element ....................................................................... 6-28

Chapter Summary ........................................................................................... 6-29

Chapter 7...................................................................................................................... 7-1

Programming with Windows Forms ............................................................................. 7-1

Overview .......................................................................................................... 7-2

An overview of the System.Windows.Forms.dll assembly ........................................ 7-3

Building a main window by hand ........................................................................ 7-6

The Application class ......................................................................................... 7-9

The Form hierarchy ......................................................................................... 7-11

Adding controls to a Form by hand ................................................................... 7-13

The Control.ControlCollection type.................................................................... 7-14

Handling mouse events .................................................................................... 7-16

Handling keyboard events ................................................................................ 7-18

Handling Paint messages ................................................................................. 7-20

Visual Studio Windows application project workspaces ........................................ 7-23

Working with the Windows Forms designer ........................................................ 7-27

Working with additional designer tools .............................................................. 7-28

Handling events with the VS IDE ........................................................................ 7-30

Working with the ‘Strip’ controls ........................................................................ 7-31

Working with the MaskedTextBox ...................................................................... 7-34

Working with the WebBrowser widget ................................................................ 7-36

Creating modal dialog boxes............................................................................ 7-37

Windows Form inheritance ............................................................................... 7-39

Chapter Summary ........................................................................................... 7-42

Chapter 8...................................................................................................................... 8-1

Reflection and Attribute-Based Programming .............................................................. 8-1

Overview .......................................................................................................... 8-2

Understanding reflection .................................................................................... 8-3

Investigating System.Type ................................................................................... 8-4

Fun with System.Type ......................................................................................... 8-6

Examining the System.Reflection namespace ...................................................... 8-11

Dynamically loading an assembly ..................................................................... 8-12

Late binding ................................................................................................... 8-14

Attribute-based programming ........................................................................... 8-17

Assembly-level attributes .................................................................................. 8-20

Building custom attributes ................................................................................. 8-21

Restricting attribute usage ................................................................................. 8-23

Attribute reflection ........................................................................................... 8-25

Chapter Summary ........................................................................................... 8-27

Chapter 9...................................................................................................................... 9-1

File IO and Object Serialization ................................................................................... 9-1

Overview .......................................................................................................... 9-2

The System.IO namespace ................................................................................. 9-3

The abstract FileSystemInfo type .......................................................................... 9-5

The DirectoryInfo type ........................................................................................ 9-7

The DriveInfo type ........................................................................................... 9-13

Understanding the stream concept .................................................................... 9-14

Working with StreamReaders and StreamWriters ................................................. 9-16

Working with BinaryReaders and BinaryWriters ................................................... 9-20

Reading and writing binary data ....................................................................... 9-22

Object serialization .......................................................................................... 9-23

Understanding object graphs ............................................................................ 9-24

Configuring objects for serialization .................................................................. 9-26

Serializing an object graph to file ...................................................................... 9-28

Serializing an object graph to a SOAP message .................................................. 9-30

Chapter Summary ........................................................................................... 9-32

Chapter 10 .................................................................................................................. 10-1

Introducing ADO.NET ............................................................................................... 10-1

Overview ........................................................................................................ 10-2

Why another data access API? .......................................................................... 10-3

The System.Data.dll assembly ........................................................................... 10-5

The role of ADO.NET data providers ................................................................. 10-8

The DataReader ............................................................................................ 10-12

Inserting new data using command objects ...................................................... 10-16

Deleting data using command objects ............................................................. 10-17

Updating data using command objects ............................................................ 10-18

Working with individual parameter objects ....................................................... 10-19

Calling stored procedures .............................................................................. 10-21

ADO.NET: The disconnected layer .................................................................. 10-23

DataSets, DataTables, DataRows, and DataColumns ........................................ 10-24

Understanding the DataAdapter...................................................................... 10-26

Modifying data in a DataSet ........................................................................... 10-29

The role of the CommandBuilder object ........................................................... 10-32

Adding table relationships .............................................................................. 10-33

Consuming table relationships ........................................................................ 10-35

Filtering the DataSet ...................................................................................... 10-36

Chapter Summary ......................................................................................... 10-38

Chapter 11 .................................................................................................................. 11-1

Advanced ADO.NET ................................................................................................. 11-1

Chapter Overview ........................................................................................... 11-2

Understanding ADO.NET data provider factories ................................................ 11-3

A complete data provider factory example ......................................................... 11-8

Working with the connection string builder ....................................................... 11-12

Working with the <connectionString> element ................................................. 11-16

DataTables as data readers ............................................................................ 11-19

Chapter Summary ......................................................................................... 11-21

Chapter 12 .................................................................................................................. 12-1

Introducing ASP.NET ................................................................................................ 12-1

Overview ........................................................................................................ 12-2

Problems with classic ASP ................................................................................. 12-3

Benefits of ASP.NET ......................................................................................... 12-5

The ASP.NET namespaces ................................................................................ 12-7

The Role of the ASP.NET Development Web Server.............................................. 12-9

Building a simple ASP.NET web page with Visual Studio .................................... 12-12

The code-page development model ................................................................ 12-21

Understanding web controls ........................................................................... 12-25

Working with web form controls ...................................................................... 12-26

The derivation of a web form control ............................................................... 12-29

Understand the issue of state management ...................................................... 12-30

Working with application and session data....................................................... 12-35

Chapter Summary ......................................................................................... 12-39

Chapter 13 .................................................................................................................. 13-1

Introducing XML Web Services ................................................................................. 13-1

Overview ........................................................................................................ 13-2

Introduction to web services .............................................................................. 13-3

The web services architecture ............................................................................ 13-6

Creating web services ...................................................................................... 13-9

Testing web services....................................................................................... 13-12

Viewing the WSDL contract ............................................................................. 13-14

Building a web service client ........................................................................... 13-16

Chapter Summary ......................................................................................... 13-21

ORDER Overview Table Of Contents

Intertech 1020 Discovery Road, Suite 145 St. Paul, MN 55121 USA Tel: 651 994 8558 Fax: 651 994 9119 Toll Free: +800 866 9884 www.Intertechcourseware.com

A

A

PROFESSIONALSERIESCourseware From The Experts

Complete C#.NET 2005 Courseware

Courseware Excerpt

© Intertech 2008— All Rights Reserved

9-1

Copyright © Intertech, Inc. 2003 – 2007

Rev: 57

Chapter 9

Reflection and Attribute Based Programming

Objectives:

Understand the role of reflection

Examine the types defined within the System.Reflection namespace

Understand how to explicitly load an external assembly

Exercise late binding to an assembly

Understand the role of attribute-based programming

Learn how to leverage predefined attributes

Build custom attributes

Reflect on attributes

9-2

Copyright © Intertech, Inc. 2003 – 2007

Rev: 57

Overview

Recall, assemblies are the basic unit of deployment in the .NET universe.

Tools such as Visual Studio .NET have integrated Object Browsers that allow you

to examine the internal types of referenced assemblies. Furthermore, external tools

such as ILDasm.exe allow you to peek into the underlying CIL code, type metadata

and assembly manifest. In addition to the design time investigation of .NET

assemblies, you can also programmatically obtain this same information using the

types defined within the System.Reflection namespace. This chapter details how to

use the types in this namespace to dynamically discover and use types within an

assembly.

The chapter wraps up with an investigation of how to insert custom metadata

into your .NET assemblies through the use of system supplied and custom

attributes. If you have a background in classic COM, you will be happy to

discover that the spirit of IDL attributes has been included and extended in the

.NET architecture.

9-3

Copyright © Intertech, Inc. 2003 – 2007

Rev: 57

Understanding Reflection

In the .NET universe, reflection is the process of runtime type discovery.

- Using reflection services, you are able to load an assembly and discover the

same sort of information as ILDasm.exe.

- You can programmatically obtain a list of all types defined within a given

module, including the methods, fields, properties and events defined by a

given type.

- You can also dynamically discover the set of interfaces supported by a given

class (or structure), the parameters of a method as well as other related

details such as base class, namespace information and so forth.

Many programmers may never need to use this reflection capability.

- However, it is very useful for developing productivity tools. For example,

VS .NET uses it extensively as does ILDasm (obviously).

- Furthermore the .NET runtime uses reflection to provide various services,

such as object serialization.

- Reflection also makes late binding possible. That is, dynamically

discovering and invoking a member of a type at runtime.

9-4

Copyright © Intertech, Inc. 2003 – 2007

Rev: 57

Investigating System.Type

Many of the items defined within the System.Reflection namespace use the

abstract System.Type class.

- This class provides a number of methods that can be used to discover the

details behind a given type. Here is a partial listing:

System.Type Member

Meaning in Life

IsAbstract

IsArray

IsClass

IsCOMObject

IsEnum

IsInterface

IsPrimitive

IsNestedPublic

IsNestedPrivate

IsSealed

IsValueType

These properties (among others) allow you to discover a

number of basic traits about the type you are referring to

(e.g. if it is an abstract method, an array, a nested class and

so forth).

GetConstructors

GetEvents

GetFields

GetInterfaces

GetMethods

GetMembers

GetNestedTypes

GetProperties

These methods (among others) allow you to obtain an

array representing the items (interface, method, property,

etc.) you are interested in.

Each method returns a related array. GetFields returns a

FieldInfo array, GetMethods returns a MethodInfo array,

etc.

Each of these methods also has a singular form (e.g.

GetMethod, GetProperty) that allows you to retrieve an

item by name, rather than as an array of all items.

FindMembers Returns an array of MemberInfo types, based on search

criteria.

GetType This method returns a Type instance given a string name.

InvokeMember This method allows late binding to a given item.