Visual Studio C# Book
Visual Studio C# Book
10/18/01
11:56 AM
Page i
C#
Your visual blueprint for
building .NET applications
TM
From
&
Best-Selling Books Digital Downloads e-Books Answer Networks e-Newsletters Branded Web Sites e-Learning
013601-X FM.F
10/18/01
11:56 AM
Page ii
Trademark Acknowledgments
Published by
Hungry Minds, Inc.
909 Third Avenue
New York, NY 10022
Permissions
maranGraphics
Certain text and illustrations by maranGraphics, Inc., used
with maranGraphics permission.
is a trademark of
Hungry Minds, Inc.
Screen shots displayed in this book are based on pre-released software and are
subject to change.
LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND AUTHOR HAVE USED
THEIR BEST EFFORTS IN PREPARING THIS BOOK. THE PUBLISHER AND AUTHOR MAKE NO
REPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS
OF THE CONTENTS OF THIS BOOK AND SPECIFICALLY DISCLAIM ANY IMPLIED WARRANTIES
OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. THERE ARE NO
WARRANTIES WHICH EXTEND BEYOND THE DESCRIPTIONS CONTAINED IN THIS
PARAGRAPH. NO WARRANTY MAY BE CREATED OR EXTENDED BY SALES REPRESENTATIVES
OR WRITTEN SALES MATERIALS. THE ACCURACY AND COMPLETENESS OF THE
INFORMATION PROVIDED HEREIN AND THE OPINIONS STATED HEREIN ARE NOT
GUARANTEED OR WARRANTED TO PRODUCE ANY PARTICULAR RESULTS, AND THE ADVICE
AND STRATEGIES CONTAINED HEREIN MAY NOT BE SUITABLE FOR EVERY INDIVIDUAL.
NEITHER THE PUBLISHER NOR AUTHOR SHALL BE LIABLE FOR ANY LOSS OF PROFIT OR ANY
OTHER COMMERCIAL DAMAGES, INCLUDING BUT NOT LIMITED TO SPECIAL, INCIDENTAL,
CONSEQUENTIAL, OR OTHER DAMAGES.
Contact maranGraphics
at (800) 469-6616 or
fax (905) 890-9434.
013601-X FM.F
10/18/01
11:56 AM
Page iii
C#
Your visual blueprint for
building .NET applications
013601-X FM.F
10/18/01
11:56 AM
Page iv
maranGraphics
www.maran.com
[email protected]
www.hungryminds.com/visual
013601-X FM.F
10/18/01
11:56 AM
Page v
CREDITS
Acquisitions, Editorial, and
Media Development
Project Editor
Jade L. Williams
Acquisitions Editor
Jen Dorsey
Product Development Supervisor
Lindsay Sandman
Copy Editor
Timothy Borek
Technical Editor
Namir Shammas
Production
Book Design
maranGraphics
Production Coordinator
Nancee Reeves
Layout
LeAndra Johnson, Adam Mancilla,
Kristin Pickett, Jill Piscitelli
Screen Artists
Ronda David-Burroughs,
David E. Gregory, Mark Harris,
Jill A. Proll
Cover Illustration
Russ Marini
Editorial Manager
Rev Mengle
Permissions Editor
Carmen Krikorian
Proofreader
Laura Albert, Laura L. Bowman,
John Greenough,
Andy Hollandbeck, Carl Pierce,
Dwight Ramsey
Indexer
TECHBOOKS Production Services
Special Help
Microsoft Corporation,
Richard Graves
ACKNOWLEDGMENTS
Hungry Minds Technology Publishing Group: Richard Swadley, Senior Vice President and Publisher; Mary Bednarek, Vice President
and Publisher, Networking; Joseph Wikert, Vice President and Publisher, Web Development Group; Mary C. Corder, Editorial
Director, Dummies Technology; Andy Cummings, Publishing Director, Dummies Technology; Barry Pruett, Publishing Director,
Visual/Graphic Design
Hungry Minds Manufacturing: Ivor Parker, Vice President, Manufacturing
Hungry Minds Marketing: John Helmus, Assistant Vice President, Director of Marketing
Hungry Minds Production for Branded Press: Debbie Stailey, Production Director
Hungry Minds Sales: Michael Violano, Vice President, International Sales and Sub Rights
013601-X FM.F
10/18/01
11:56 AM
Page vi
AUTHORS ACKNOWLEDGMENTS
Eric Butow
I would like to acknowledge all the people at Hungry Minds for their support and assistance in making
this book possible, especially my editors, Jade Williams and Jennifer Dorsey.
Tommy Ryan
I would like to thank all of the hardworking people at Hungry Minds for helping produce this book
especially Jennifer Dorsey, Jade Williams, and other editors. Jennifer made sure that I was paid (very
important) and Jade did an great job of explaining how to write with style.
To the clients that I have worked with during the past couple of years for challenging me to be a better
consultant, including Nick Callivas, Brian Blinco, Jay Dalke, Bob Hughes, and Harwell Thrasher.
To my previous employeer, Extreme Logic, and all of the exceptional people that helped me mature as a
consultant and an educator. This company has taught me some valuable lessons.
To my colleagues at W.L. Gore and Associates that helped me start my professional career, including
John Reaney, Mark Fundakowsi, Diccon Bancroft, John Pysczynski, Pamela Perdue, Erik Nightwine,
Debra Raup, Ray Edmanson, Bob McCleary, Lawrence Anderson, Wolfgang Holma and Line 10
Production Team; the WinCC Team at Siemens that helped me in my transition to being a Microsoft
geek, including Emilio Matt, Rob Bohm, Bob Meads, Rich Miceli, Charlie Moore, Jrg Allmendinger, and
Rene Wolf; and my extended family and friends for the support in the things outside of work, including
Joe and Rosemarie Markiewicz, Robert and Donna Philips, Joe and Jan Markiewicz, and Chuck and
Mary Hanson, Rob and Gretchen Pfeiffer, and Reverend Joe Ciccone CSP.
A special thanks goes out to my brother, Danny Ryan. Without Danny, I would not have taken or
completed my contribution to this book or the ASP.NET book. Danny is an excellent partner and I look
forward to the great things that we will accomplish in our new endeavors.
013601-X FM.F
10/18/01
11:56 AM
Page vii
Eric Butow
To my grandmother, who instilled her Midwestern sensibilities in me.
Tommy Ryan
To my eternal partner, Linda.
013601-X FM.F
10/18/01
11:56 AM
Page viii
TABLE OF CONTENTS
viii
013601-X FM.F
10/18/01
11:56 AM
Page ix
C#:
Your visual blueprint for
building .NET applications
ix
013601-X FM.F
10/18/01
11:56 AM
Page x
TABLE OF CONTENTS
7) USING ARRAYS
View Information About Arrays ......................................................................................136
Enter Single-Dimensional Arrays ....................................................................................138
Add Multidimensional Arrays ........................................................................................140
Program Array-of-Arrays ................................................................................................142
Iterate Through Array Elements ......................................................................................144
Sort Arrays ........................................................................................................................146
Search Arrays ....................................................................................................................148
Implement a Collections Class ......................................................................................150
Program Structs ................................................................................................................152
Add an Indexer ................................................................................................................154
Include Enumerations ......................................................................................................156
013601-X FM.F
10/18/01
11:56 AM
Page xi
C#:
Your visual blueprint for
building .NET applications
9) ACCESSING PROPERTIES
View Information About Properties ..............................................................................184
Compare Properties and Indexers ................................................................................186
Program Property Accessors ..........................................................................................188
Declare Abstract Properties ............................................................................................192
Include Properties on Interfaces ....................................................................................194
xi
013601-X FM.F
10/18/01
11:56 AM
Page xii
TABLE OF CONTENTS
xii
013601-X FM.F
10/18/01
11:56 AM
Page xiii
C#:
Your visual blueprint for
building .NET applications
INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .296
xiii
013601-X FM.F
10/18/01
11:56 AM
Page xiv
xiv
013601-X FM.F
10/18/01
11:56 AM
Page xv
C#:
Your visual blueprint for
building .NET applications
xv
023601-X Ch01.F
10/18/01
11:57 AM
Page 2
C#
INTRODUCTION TO C#
The Birth of C#
Integration
023601-X Ch01.F
10/18/01
11:57 AM
Page 3
DLLs
XML
Declaring Variables
Assignments
C#:
Visual C++:
Java:
C#:
Visual C++:
Java:
int x;
int x=3;
int x;
int x=3;
int x;
int x=3;
xValue=7;
xValue=7;
xValue=7;
WHILE Loops
FOR Loops
C#:
C#:
for (int i = 1; i <= 10; i++)
Console.WriteLine("The number is {0}", i);
Visual C++:
Visual C++:
Java:
Java:
for (int i = 1; i < 11; i++)
System.out.println("The number is " + i);
If-Else Statements
C#:
Visual C++:
Java:
023601-X Ch01.F
10/18/01
11:57 AM
Page 4
C#
The Start page lets you log into the Microsoft Developers
Network (MSDN) Web site directly from the MDE, so you
can receive the latest information from Microsoft about
Visual Studio, get technical help from fellow Visual Studio
users at Microsofts online forum, and search for
information online.
Visual Studio .NET also lets you create and change your
profile so that you can view windows, enter keyboard
commands, and receive help for the programming language
in which you are working. For example, if you have used an
older version of Visual Studio in the past and you prefer to
use the old windows and keyboard commands, Visual Studio
lets you use Visual Basic and C++ windows and menus.
Programs
Click Start.
Click Programs.
The Microsoft
Development Environment
window appears displaying
the VS Start Page.
023601-X Ch01.F
10/18/01
11:57 AM
Page 5
023601-X Ch01.F
10/18/01
11:57 AM
Page 6
C#
fter you start the MDE window, you can open a new
project. A project contains all the files related to your
C# program. After you determine the type of C#
program you want to write, Visual Studio creates all of the
project files you need to start programming. Visual Studio
contains project templates that let you create different
types of programs. The MDE window lets you create eight
different projects so you can tailor your C# program to the
needs of your program users.
You can create three different application types, each with a
different user interface. First, you can create a Windows
application that has a graphical, form-based interface. You
can create a console application with a character-based
interface. Finally, you can create a Web application that
Visual C# Projects
Console
Applica...
Projects folder.
project.
Click Open.
023601-X Ch01.F
10/18/01
11:57 AM
Page 7
Start Page
Visual C# Projects
FirstProject.Class1
Main(string[] args)
Class1.cs
Console
Applica...
Click OK.
023601-X Ch01.F
10/18/01
11:57 AM
Page 8
C#
online help and resources from the Start menu. When you
access help on the Web or newsgroups, the MDE parent
window behaves as a window in your Internet browser
would, so you can get your help directly from the MDE
window without having to start an Internet browser.
The MDE window also contains links to help from both the
Microsoft Web site and online newsgroups where you can
leave and read messages from other C# programmers. You
can also search the Microsoft Web site for help with specific
topics.
023601-X Ch01.F
10/18/01
11:57 AM
Page 9
023601-X Ch01.F
10/18/01
11:57 AM
Page 10
C#
Visual C# Projects
ASP.NET
Web A...
appears.
Web application.
Click OK.
023601-X Ch01.F
10/18/01
11:57 AM
Page 11
Solution Explorer. . .
11
023601-X Ch01.F
10/18/01
11:57 AM
Page 12
C#
New
File
Ctrl+N
General
HTML
Page
Web Form
12
023601-X Ch01.F
10/18/01
11:57 AM
Page 13
Click
to select a target
schema from the drop-down
list.
Click OK.
13
033601-X Ch02.F
10/18/01
11:57 AM
Page 14
C#
WindowsApplication3
Form1.cs
14
033601-X Ch02.F
10/18/01
11:57 AM
Page 15
Form1.cs
in the tree.
15
033601-X Ch02.F
10/18/01
11:57 AM
Page 16
C#
Form1.cs
application project.
16
033601-X Ch02.F
10/18/01
11:57 AM
Page 17
Visual C# Language
Visual C# Language
Language book.
17
033601-X Ch02.F
10/18/01
11:57 AM
Page 18
C#
As with the Contents window, you can filter the topics that
appear in the Index window, according to different parts of
Visual Studio .NET. If you want to view only C# information,
you can set the filter so that the Index window presents
only C# topics. You can also set the filter so the Index
window presents topics about and related to C#.
You can view related information in any help topic page
link and in the Index Results window directly below the
help topic page. The filter that you set in the Index window
does not affect these page and Index Results links.
Index. . .
Ctrl+Alt+F2
Index
Click Help.
Click Index.
18
033601-X Ch02.F
10/18/01
11:57 AM
Page 19
19
033601-X Ch02.F
10/18/01
11:57 AM
Page 20
C#
Search. . .
Ctrl+Alt+F3
Click Help.
Click Search.
Type class.
Click the Search button.
The Help Search in
20
033601-X Ch02.F
10/18/01
11:57 AM
Page 21
Search
Visual C#
Click
beside the
Filtered by field.
21
033601-X Ch02.F
10/18/01
11:57 AM
Page 22
C#
Toolbox
Form1
Type Here
Form1.cs
Toolbox
Form1.cs
Ctrl+Alt+X
Click View.
Click Toolbox.
The MainMenu
component appears at the top
of the form.
22
033601-X Ch02.F
10/18/01
11:57 AM
Page 23
Toolbox
:-)VideoSoft FlexArray Control
Form1.cs
Customize Toolbox. . .
Right-click the
Toolbox window.
Click OK.
The vsFlexArrayCtrl COM
23
033601-X Ch02.F
10/18/01
11:57 AM
Page 24
C#
Form1.cs
Form1.cs
All
Task List
Show Tasks
24
033601-X Ch02.F
10/18/01
11:57 AM
Page 25
Form1.cs
Form1.cs
Create form
High
A strikethrough line
25
033601-X Ch02.F
10/18/01
11:57 AM
Page 26
C#
Form1.cs
Form1.cs
Properties
Properties
Text
application project.
26
Text
Form1
033601-X Ch02.F
10/18/01
11:57 AM
Page 27
Form1.cs
Form1.cs
Properties
Properties
Text
Press Enter.
Text
27
033601-X Ch02.F
10/18/01
11:57 AM
Page 28
C#
Build
Form1.cs
Custom 1
Customize
Right-click a toolbar.
Click New.
Type the new toolbar
name.
Click OK.
28
033601-X Ch02.F
10/18/01
11:57 AM
Page 29
Solution Explorer - . . .
File
Form1.cs
Form1.cs
Right-click the
custom toolbar.
Click to select a
command category.
29
033601-X Ch02.F
10/18/01
11:57 AM
Page 30
C#
DELETE A TOOLBAR
f you find that you no longer use a toolbar and you want
to use the extra space for other features in the MDE
window, like the parent window for editing code, the
MDE window lets you delete a toolbar entirely from your
system.
At the left of every toolbar is a series of dark gray lines or
hashmarks. These lines indicate the start of the toolbar and
where you can place the mouse pointer so you can move
the toolbar around on the screen. You can determine
whether the toolbar will remain at the top of the screen or
float around the screen as its own window.
DELETE A TOOLBAR
Standard
Standard
Customize. . .
Form1.cs
Form1.cs
Click Standard.
30
033601-X Ch02.F
10/18/01
11:57 AM
Page 31
Technical Support
Technical Support
Form1.cs
Form1.cs
Help
Help
The Customize
window appears.
31
033601-X Ch02.F
10/18/01
11:57 AM
Page 32
C#
Options
32
033601-X Ch02.F
10/18/01
11:57 AM
Page 33
Text
33
033601-X Ch02.F
10/18/01
11:57 AM
Page 34
C#
Solution Explorer - . . .
Form1.cs
Click Window.
34
033601-X Ch02.F
10/18/01
11:57 AM
Page 35
Solution Explorer - . . .
Form1.cs
Form1.cs
35
043601-X Ch03.F
10/18/01
11:58 AM
Page 36
C#
OPEN A PROJECT
You can also change your default directory within the MDE
window so you can save and access files from that
directory. When you change your default directory before
you create your first C# program, you will save the time it
takes to move all your programs to that new default
directory.
The Look in field contains a directory tree so you can
navigate throughout your computer and/or network file and
directory structure. After you select the directory in the
Look in field, the Open Project window displays the
directory files.
OPEN A PROJECT
36
043601-X Ch03.F
10/18/01
11:58 AM
Page 37
MyFirstApplication.sln
Click Open.
37
043601-X Ch03.F
10/18/01
11:58 AM
Page 38
C#
38
043601-X Ch03.F
10/18/01
11:58 AM
Page 39
RESULT:
using System;
class Class1;
{
public static void Main(string[] args)
if (args.Length == 0)
{
Console.Writeline("Please enter a numeric
argument: ");
return 1;
}
}
Please enter a
numeric argument: 1
Solution Explorer...
Form1.cs
39
043601-X Ch03.F
10/18/01
11:58 AM
Page 40
C#
40
043601-X Ch03.F
10/18/01
11:58 AM
Page 41
RESULT:
using System;
public EnumClass
{
enum WeekDays {Mon=1, Tues, Wed, Thurs, Fri, Sat,
Sun}
public static void Main()
{
int x = (int) WeekDays.Wed;
Console.WriteLine("The Wednesday enum value is
{0}", x);
}
}
filename.
41
043601-X Ch03.F
10/18/01
11:58 AM
Page 42
C#
42
043601-X Ch03.F
10/18/01
11:58 AM
Page 43
RESULT:
using System;
public BoxClass
{
public static void Main()
{
int TiggerAge = 11;
object box = TiggerAge; // boxes the TiggerAge
value
int UnBoxedAge = (int)box; // Unboxes the
value
Console.WriteLine("The unboxed value is {0}",
UnBoxedAge);
}
}
filename.
43
043601-X Ch03.F
10/18/01
11:58 AM
Page 44
C#
ADD OPERATORS
ADD OPERATORS
Console
Applicatio
043601-X Ch03.F
10/18/01
11:58 AM
Page 45
RESULT:
using System;
class Multiply {
int number;
public Integer(int number) {
Multiply Value: 30
this.number = number; }
public static Multiply operator *(Multiply x, Multiply y) {
return new Multiply(x.number * y.number); }
class Output {
public static void Main() {
Multiply a = new Multiply(3,5);
Multiply b = new Multiply(1,2);
Console.WriteLine("Multiply Value: {0}", (a * b)); }
}
filename.
45
043601-X Ch03.F
10/18/01
11:58 AM
Page 46
C#
INSERT ATTRIBUTES
INSERT ATTRIBUTES
Console
Applicatio
46
043601-X Ch03.F
10/18/01
11:58 AM
Page 47
RESULT:
using System;
[Obsolete]
class GetAttribute
{
static void Main(string[] args)
{
Type x = typeof(GetAttribute);
object[] xget = x.GetCustomAttributes();
Console.WriteLine(The custom attribute is:);
foreach (object y in xget)
Console.WriteLine (y);
}
}
CONTINUED
47
043601-X Ch03.F
10/18/01
11:58 AM
Page 48
C#
INSERT ATTRIBUTES
48
043601-X Ch03.F
10/18/01
11:58 AM
Page 49
filename.
49
043601-X Ch03.F
10/18/01
11:58 AM
Page 50
C#
ENTER CLASSES
lasses provide the functionality your C# program
needs to perform its tasks. Three types of members
comprise a class: data members, such as userentered fields; function members that include methods,
properties, and operators; and type members such as value
types.
Before you add the class in the Add Class Wizard, you have
to tell Visual C# to add a class in the Class View window.
When you add a class in the Class View window, the Add
Class Wizard appears so you can enter the class
information. After you enter the information, the class
code appears in the parent window.
Visual C# lets you add classes using the Add Class Wizard.
This three-page wizard asks you questions about the types
of classes that you want to add, and after the wizard
finishes, Visual C# enters the class types in your program
automatically without making you put in the extra work of
defining the classes in code.
ENTER CLASSES
Console
Applicatio
50
043601-X Ch03.F
10/18/01
11:58 AM
Page 51
RESULT:
The summary does not display on your screen, but when
you or someone else displays the code for the program,
the comments appear within the code.
Solution Explorer...
Solution Explorer...
Classes
Class1.cs
Click Add.
Click Add Class.
CONTINUED
51
043601-X Ch03.F
10/18/01
11:58 AM
Page 52
C#
ENTER CLASSES
Click Open.
52
Click Add.
Click Add Class.
043601-X Ch03.F
10/18/01
11:58 AM
Page 53
TYPE THIS:
RESULT:
Click Finish.
53
043601-X Ch03.F
10/18/01
11:58 AM
Page 54
C#
Console
Applicatio
54
043601-X Ch03.F
10/18/01
11:58 AM
Page 55
JAVA
C++
//
//
//
/* comment */
/* comment */
/* comment */
Comments
a comment by placing /* at
the beginning and an */ at the
end of the comment.
filename.
55
043601-X Ch03.F
10/18/01
11:58 AM
Page 56
C#
Console
Applicatio
56
043601-X Ch03.F
10/18/01
11:58 AM
Page 57
filename.
Rename Class1 as
Type the
Hello.
Console.WriteLine
statement that announces
your program to the world.
appears.
57
043601-X Ch03.F
10/18/01
11:58 AM
Page 58
C#
Console
Applicatio
58
043601-X Ch03.F
10/18/01
11:58 AM
Page 59
59
043601-X Ch03.F
10/18/01
11:58 AM
Page 60
C#
ACCESS DOCUMENTATION
These sources include online text files that provide help and
online resources from the Microsoft Web site. The online
help files and Web pages appear directly within the MDE
window so you do not have to close the MDE window and
open a new one.
Visual Studio .NET installs online help as part of its
installation process. You can access these files directly from
the MDE window menu bar. Visual Studio .NET groups
these files by topic so you can find what you want easily. If
you need more powerful search features, you can search by
keywords and other criteria such as limiting results to Visual
C# topics. When you view a help page, it appears in the
parent window as another tab so you can switch between
your help page and C# program.
When you view the online help features, those Web pages
appear in the parent window as well. You can navigate
these pages just as you would in a Web browser so you can
find the information you want. The MDE window also
includes a built-in online search feature so you can find
what you need online more effectively.
ACCESS DOCUMENTATION
Visual C#
60
Click
Filter field.
043601-X Ch03.F
10/18/01
11:58 AM
Page 61
61
043601-X Ch03.F
10/18/01
11:58 AM
Page 62
C#
62
password.
Click Submit.
043601-X Ch03.F
10/18/01
11:58 AM
Page 63
340056
[email protected]
63
053601-X Ch04.F
10/18/01
11:58 AM
Page 64
C#
Index...
Ctrl+Alt+F2
Visual C#
64
Click Help.
Click Index.
to select Visual
C# from the Filtered by
drop-down list.
053601-X Ch04.F
10/18/01
11:58 AM
Page 65
Component Functionality
page appears in the parent
window.
65
053601-X Ch04.F
10/18/01
11:58 AM
Page 66
C#
PROGRAM CLASSES
bject-oriented programming languages use classes
that act as containers for data elements in your
program. Classes let other elements in your
program, such as methods, process that data and perform
functions such as displaying a calculation result as output.
PROGRAM CLASSES
Console
66
053601-X Ch04.F
10/18/01
11:58 AM
Page 67
When you add a class in the Add Class Wizard, one of the
first things you must do is identify a namespace. C#
automatically adds a new namespace when you create a new
class, but if you add a class within a class, you can specify a
new namespace.
TYPE THIS:
RESULT:
using System;
namespace NewSpace
{
class NewClass
{
public static void Main(string[] args)
{
Console.WriteLine("This class has the namespace
NewSpace.");
}
}
67
053601-X Ch04.F
10/18/01
11:58 AM
Page 68
C#
ADD A CLASS
ADD A CLASS
Console
Applicatio
68
053601-X Ch04.F
10/18/01
11:58 AM
Page 69
Java
super
Java
abstract
C++
__super
C++
abstract
C#
base
C#
abstract
Java
class A extends B
Java
final
C++
class A public B
C#
sealed
C#
class A B
AddClass
Black Text
Add Class...
Add
Click Add.
Right-click AddClass in
the Class View window.
CONTINUED
69
053601-X Ch04.F
10/18/01
11:58 AM
Page 70
C#
ADD A CLASS
public
70
Click
to select the
access level from the
drop-down list.
Click Finish.
053601-X Ch04.F
10/18/01
11:58 AM
Page 71
RESULT:
using System;
// This is an abstract class as denoted by the
abstract keyword.
abstract class AbClass
{
static void Main(static[] args)
{
int string a = An abstract class.;
Console.WriteLine(a);
}
}
An abstract class.
AddClass
Click {} AddClass.
The NewClass entry
appears in the tree.
Click NewClass.
71
053601-X Ch04.F
10/18/01
11:58 AM
Page 72
C#
Console
Applicatio
72
053601-X Ch04.F
10/18/01
11:58 AM
Page 73
the information
and the inheriting class that
processes the information
for output.
filename.
on the screen.
73
053601-X Ch04.F
10/18/01
11:58 AM
Page 74
C#
Console
Applicatio
74
053601-X Ch04.F
10/18/01
11:58 AM
Page 75
You can add the this keyword so a class or struct can overload
existing constructors and call one of its own constructors instead.
TYPE THIS:
RESULT:
using System;
class Class1 {
public int a;
public Class1() : this (2) //gives a the value of 2 { }
2
4
public Class1(int b) {
a = b //overloads the existing constructor }
static void Main(string[] args) {
Class1 x1 = new Class1();
Class1 x2 = new Class1(4); // 4 is the new value per
the overloaded constructor
Console.WriteLine(x1.a);
Console.WriteLine(x2.a);
}
}
75
053601-X Ch04.F
10/18/01
11:58 AM
Page 76
C#
76
053601-X Ch04.F
10/18/01
11:58 AM
Page 77
RESULT:
filename.
77
053601-X Ch04.F
10/18/01
11:58 AM
Page 78
C#
INSERT DESTRUCTORS
hen you create constructors you are setting the
stage to place your objects somewhere in memory.
However, there may be times where you have to
remove those objects from memory either to free up the
space for other objects or because you want to clean out
those objects that no longer apply to your program. C#
gives you the ability to delete these objects by using
destructors.
INSERT DESTRUCTORS
Console
Applicatio
78
053601-X Ch04.F
10/18/01
11:58 AM
Page 79
filename.
79
053601-X Ch04.F
10/18/01
11:58 AM
Page 80
C#
PROGRAM STRUCTS
PROGRAM STRUCTS
Console
Applicatio
80
053601-X Ch04.F
10/18/01
11:58 AM
Page 81
RESULT:
using System;
class BaseClass
{
public static void Main()
{
Console.WriteLine("The base class.");
}
}
struct Inherit : BaseClass
coordinates.
81
053601-X Ch04.F
10/18/01
11:58 AM
Page 82
C#
PROGRAM STRUCTS
tructs are more efficient when you have only a limited
range of values that an object must refer to. This makes
a struct a good choice when you define an array of
values because a struct will process only the array, not each
separate value in the array.
82
053601-X Ch04.F
10/18/01
11:58 AM
Page 83
RESULT:
Declaring your struct information and the System.Runtime.InteropServices namespace
ensures that you can run your program. After you declare your struct you can enter the struct
constructor.
filename.
83
053601-X Ch04.F
10/18/01
11:58 AM
Page 84
C#
84
053601-X Ch04.F
10/18/01
11:58 AM
Page 85
filename.
85
063601-X Ch05.F
10/18/01
11:59 AM
Page 86
C#
Index...
Programs
86
Ctrl+Alt+F2
Click Index.
063601-X Ch05.F
10/18/01
11:59 AM
Page 87
Index
appears.
87
063601-X Ch05.F
10/18/01
11:59 AM
Page 88
C#
Console
Applicatio
n
Properties
88
063601-X Ch05.F
10/18/01
11:59 AM
Page 89
RESULT:
15
filename.
89
063601-X Ch05.F
10/18/01
11:59 AM
Page 90
C#
Properties
90
063601-X Ch05.F
10/18/01
11:59 AM
Page 91
You can display the actual value type for any C# type using
the method GetType().
TYPE THIS:
RESULT:
using System;
class Type;
{
public static void Main()
{
Console.WriteLine(15500L.GetType());
}
}
Uint64
filename.
91
063601-X Ch05.F
10/18/01
11:59 AM
Page 92
C#
Properties
92
063601-X Ch05.F
10/18/01
11:59 AM
Page 93
93
063601-X Ch05.F
10/18/01
11:59 AM
Page 94
C#
If you need even larger numbers, the double type gives you
a far greater range 5.0 x 10 324 to 1.7 x 10308 and it
rounds off numbers to 15 or 16 digits depending on the
number. Double numbers require no suffix after the value.
The decimal type does not give you the range of the
floating point type the decimal type ranges from 1.0 x
10 28 to 7.9 x 1028 but it does give you greater precision by
rounding off numbers to 28 or 29 digits depending on the
number.
You must denote a decimal type by using the suffix m after
the decimal value. If you do not use the f and m suffixes for
floating-point and decimal values, the value will be treated
as a double-value, and your project cannot compile.
94
063601-X Ch05.F
10/18/01
11:59 AM
Page 95
RESULT:
X
X
filename.
95
063601-X Ch05.F
10/18/01
11:59 AM
Page 96
C#
Console
Applicatio
Properties
96
063601-X Ch05.F
10/18/01
11:59 AM
Page 97
RESULT:
The value of x is greater than zero.
filename.
97
063601-X Ch05.F
10/18/01
11:59 AM
Page 98
C#
You can assign values of any type to the variables that you
include in the object statement. When you convert
reference types to value types and vice versa, you do so by
declaring those types within the object type before you
convert.
Console
Applicatio
Properties
98
063601-X Ch05.F
10/18/01
11:59 AM
Page 99
If you want to determine if two strings are the same, such as a user-entered
password matching the stored password, you can use the equality (==) and
inequality (!=) operators for testing whether two strings are the same as
you would with two values in a value type declaration.
RESULT:
TYPE THIS:
using System;
class EqualityTest;
{
int x = 4;
int y = 5
public static void Main()
{
if (x != 0)
{
Console.WriteLine("The value of x is greater than zero.");
}
if (x == 0)
{
Console.WriteLine("The value of x is zero.");
}
}
}
The value of x is
greater than zero.
filename.
99
063601-X Ch05.F
10/18/01
11:59 AM
Page 100
C#
Properties
100
063601-X Ch05.F
10/18/01
11:59 AM
Page 101
RESULT:
using System;
interface IntBase1
{
void IBMethod1();
}
interface IntBase2
{
void IBMethod2();
}
interface Int1: IntBase1, IntBase2
{
void Method1();void Method2();
}
CONTINUED
101
063601-X Ch05.F
10/18/01
11:59 AM
Page 102
C#
project.
appears onscreen.
102
appears.
063601-X Ch05.F
10/18/01
11:59 AM
Page 103
filename.
103
063601-X Ch05.F
10/18/01
11:59 AM
Page 104
C#
Console
Applicatio
Properties
104
063601-X Ch05.F
10/18/01
11:59 AM
Page 105
You can unbox an object with a boxed object value. For example, if you see
an object statement with a = 5, you want to move the number 5 from the
object to an integer, or else the compiler will return an error. You can test
whether an object value has been boxed correctly using the try and catch
arguments.
RESULT:
TYPE THIS:
using System;
public class Unbox
{
int a = 5;
object x = a // boxes a into object x
try
{
int b = (int) x;
Console.WriteLine("The integer unboxed successfully.");
}
catch (InvalidCastException e) // If there is an error, the catch argument
catches it.
{
Console.WriteLine("{0} Unboxing error!",e);
}
filename.
105
063601-X Ch05.F
10/18/01
11:59 AM
Page 106
C#
When you enter the unsafe keyword in code, you tell the
compiler and the Visual Studio .NET runtime environment
(the Common Language Runtime) that the garbage
collector should not manage those memory blocks that
have been allocated in the unsafe argument. You point to
the memory blocks to reserve by using the pointer type.
Console
Applicatio
Properties
106
063601-X Ch05.F
10/18/01
11:59 AM
Page 107
RESULT:
using System;
class Pointer
{
int x, y;
unsafe static void Main()
{
Pointer test = new Pointer();
Fixed(int* p1 = &test.x)
Fixed (int* p2 = &test.y)
*p1 = 2;
*p2 = 4;
Console.WriteLine(test.x);
Console.WriteLine(test.y);
}
2
4
6
filename.
107
063601-X Ch05.F
10/18/01
11:59 AM
Page 108
C#
The void type indicates that the method does not return a
value and/or take any parameters. Many statements will use
the void type that precedes the method so the program
will understand that it will take the implementation
information from your method and the method will not
accept any parameters or return any value.
Console
Applicatio
Properties
108
063601-X Ch05.F
10/18/01
11:59 AM
Page 109
RESULT:
This code hides the Main method in the base class
so only the objects in the inherited class will receive
the implementation instructions from the Main
method. Because the void type precedes the Main
method in the code, the method will not return any
values or accept any variables.
filename.
109
063601-X Ch05.F
10/18/01
11:59 AM
Page 110
C#
information into your program and you can use the set
accessor for assigning that user input to a value. The get
accessor is similar to a method in that it must return a value
of the property type. For example, if the property for the
get accessor is character based, the value must be a string.
Add
Console
Applicatio
110
Add Property...
Right-click Class1.
Click OK.
appears.
Click Add.
063601-X Ch05.F
10/18/01
11:59 AM
Page 111
RESULT:
The state of the object
changes every time
your project accesses
the Number field.
int
Click Finish.
111
063601-X Ch05.F
10/18/01
11:59 AM
Page 112
C#
Class1
Console
Applicatio
112
Click OK.
appears.
063601-X Ch05.F
10/18/01
11:59 AM
Page 113
Class1
public
Add
Add Indexer...
Right-click Class1.
Click Add.
Click Add Indexer.
Click
to select the
indexer access type from
the drop-down list.
CONTINUED
113
063601-X Ch05.F
10/18/01
11:59 AM
Page 114
C#
From there you can enter the parameter name from a list of
parameters that meet the object type requirements. For
example, if your interface index is an object, the list of
available parameter names will be those in the class that
associate with the object type. You can add and remove as
many parameters from the indexer list as you want.
int
int
int
int
Click
to select one
of the 15 indexer types from
the drop-down list.
114
Click
to select the
indexer parameter type
from the drop-down list.
063601-X Ch05.F
10/18/01
11:59 AM
Page 115
int
int Param1
indexer.
115
073601-X Ch06.F
10/18/01
11:59 AM
Page 116
C#
Index
116
Click Help.
Crtl+Alt+F2
Click Index.
073601-X Ch06.F
10/18/01
12:00 PM
Page 117
methods, adding in
adding in C#
adding in C#
117
073601-X Ch06.F
10/18/01
12:00 PM
Page 118
C#
ADD A METHOD
s with a property and an indexer, C# gives you two
ways to add a method. If you like the step-by-step
functionality provided by a wizard, the C# Add
Method Wizard lets you add a method automatically. You
can also add a method in code.
After you enter the method keyword, you can enter the
optional method declarations. These declarations include
various attributes, method modifiers, the return type, and
then the name of the method itself. Then you begin to add
the information within your method.
When you add a method in code you start with the method
keyword. You can add information that precedes the
keyword: whether the method is static or non-static (the
default is non-static) and whether the method contains a
void type. The void type renders the method invisible
where it takes on no parameters and returns no values.
ADD A METHOD
Visual C# Projects
Console
Application
118
073601-X Ch06.F
10/18/01
12:00 PM
Page 119
You use the return keyword in all methods except one: the
void type. When you specify the void method type, you do
not need to include the return keyword because the return
type is automatically void.
TYPE THIS:
RESULT:
using System;
class VoidTest
{
public static void Main()
{
int diameter = 25;
Console.WriteLine("The diameter is {0}", diameter);
}
}
The diameter is 25
Class View - M. . .
Method
{}Method
Class1
Void
Public
int
Add Method . . .
Add
119
073601-X Ch06.F
10/18/01
12:00 PM
Page 120
C#
ADD A METHOD
void
void
int
120
int
Click Add.
Int Parameter1
073601-X Ch06.F
10/18/01
12:00 PM
Page 121
RESULT:
using System;
public class OutTest
{
public static int Output(out int a)
{
a = 25;
return 0;
}
public static void Main()
{
int a;
Console.WriteLine(Output(out a));
Console.WriteLine(a);
}
}
0
25
void
int
int Parameter1
Comment field.
Click Finish.
121
073601-X Ch06.F
10/18/01
12:00 PM
Page 122
C#
Visual C# Projects
Console
Application
122
073601-X Ch06.F
10/18/01
12:00 PM
Page 123
RESULT:
using System;
public class Params
{
public static void Parameter(params int[] list)
{
for ( int x = 0 ; x < list.Length ; x++
)
Console.WriteLine(list[x]);
Console.WriteLine();
}
public static void Main()
{
Parameter(10, 15, 20);
}
}
10
15
20
Class1
void
StaticMethod
int
Add Method
Add
123
073601-X Ch06.F
10/18/01
12:00 PM
Page 124
C#
void
Class1.cs
int
Click Add.
The added parameter
name appears in the
Parameter list field.
124
Click Finish.
073601-X Ch06.F
10/18/01
12:00 PM
Page 125
filename.
125
073601-X Ch06.F
10/18/01
12:00 PM
Page 126
C#
Visual C# Projects
Console
Applications
126
073601-X Ch06.F
10/18/01
12:00 PM
Page 127
RESULT:
using System;
public class Name {
public string first;
public string last;public Person () { }
public Person (string first, string last) {
this.first = first;
this.last = last;
}
class Main: Person {
public static void Main() {
Console.Write("First name? ");
String first = Console.ReadLine(); //accepts input
Person a = new Person (name, id);
Console.WriteLine("First name: {0}", a.first);
}
}
Class1
void
int
Add Method
Add
Right-click the
class name.
The C# Method
Wizard appears.
127
073601-X Ch06.F
10/18/01
12:00 PM
Page 128
C#
void
int
128
Click Finish.
One method.
073601-X Ch06.F
10/18/01
12:00 PM
Page 129
You can represent a class object in the memberaccess format as well for precise representation
of your object. Though the member-access E.M
format is the same as with static methods, the E
cannot represent a type. Instead, the E must
represent the class instance. Usually the
member-access format does not include the
identifier signified by M because the instance
expression signified by E is all the information
needed.
Another reason for using the member-access
format is that you can perform a member
lookup. A member lookup evaluates simplename or member-access forms in an expression
or statement.
filename.
129
073601-X Ch06.F
10/18/01
12:00 PM
Page 130
C#
ENTER DELEGATES
ENTER DELEGATES
Visual C# Projects
Console
Applications
073601-X Ch06.F
10/18/01
12:00 PM
Page 131
TYPE THIS:
using System;
delegate void Del1(string x)
class Class1
{
public static void On(string x)
{
Console.WriteLine("Switch goes on.", x);
}
public static void Off(string x)
{
Console.WriteLine("Switch goes off.", x);
}
public static void Main();
{
Del1 a, b, c;
a = new Del1(On);
b = new Del1(Off);
c = a + b;
Console.WriteLine("The two switch states:");
c;
}
}
filename.
131
073601-X Ch06.F
10/18/01
12:00 PM
Page 132
C#
PROGRAM EVENTS
PROGRAM EVENTS
Visual C# Projects
Console
Applications
073601-X Ch06.F
10/18/01
12:00 PM
Page 133
filename.
133
073601-X Ch06.F
10/18/01
12:00 PM
Page 134
C#
Visual C# Projects
Form1.cs
Console
Applications
134
073601-X Ch06.F
10/18/01
12:00 PM
Page 135
RESULT:
When you run your program and the form appears, the
form will click when you press down with the left mouse
button.
Properties
Click
name.
135
083601-X Ch07.F
10/18/01
12:00 PM
Page 136
C#
Properties
136
Click Help.
Click Index.
083601-X Ch07.F
10/18/01
12:00 PM
Page 137
USING ARRAYS
Index
appears.
field.
Click
to select Visual
C# in the Filtered by dropdown menu.
137
083601-X Ch07.F
10/18/01
12:00 PM
Page 138
C#
Properties
138
083601-X Ch07.F
10/18/01
12:00 PM
Page 139
USING ARRAYS
filename.
139
083601-X Ch07.F
10/18/01
12:00 PM
Page 140
C#
Properties
140
083601-X Ch07.F
10/18/01
12:00 PM
Page 141
USING ARRAYS
filename.
141
083601-X Ch07.F
10/18/01
12:00 PM
Page 142
C#
PROGRAM ARRAY-OF-ARRAYS
PROGRAM ARRAY-OF-ARRAYS
Properties
142
083601-X Ch07.F
10/18/01
12:00 PM
Page 143
USING ARRAYS
filename.
143
083601-X Ch07.F
10/18/01
12:00 PM
Page 144
C#
Properties
144
083601-X Ch07.F
10/18/01
12:00 PM
Page 145
USING ARRAYS
You can also iterate through an array using the for statement if you
want. The for statement requires you to match the array with the
indexing operation whereas the foreach statement does not.
RESULT:
TYPE THIS:
using System;
class Class1;
{
public static void Main()
{
int odd = 0, even = 0;
int[] arr = {1, 2, 3, 5, 7, 11};
for (int Index = 0; Index < arr.Count; Index++)
{
if (i%2 == 0)
even++;
else
odd++;
}
Class1 number = (Class1) arr[Index];
Console.WriteLine("There are {0} odd numbers and {1} even numbers.", odd, even);
}
}
There are 5
odd numbers
and 1 even
number.
filename.
145
083601-X Ch07.F
10/18/01
12:00 PM
Page 146
C#
SORT ARRAYS
SORT ARRAYS
Properties
146
083601-X Ch07.F
10/18/01
12:00 PM
Page 147
USING ARRAYS
When you sort arrays that have strings that contain capital
letters, C# considers those strings to be lower on the
alphabetization list than strings with lowercase letters.
TYPE THIS:
RESULT:
using System;
class SortArray;
{
public static void Main()
{
string[] names = {"too", "two", "To", "Too"};
Array.Sort(names);
foreach (string value in names)
{
Console.WriteLine("The word is {0}", value);
}
}
}
The
The
The
The
word
word
word
word
is
is
is
is
too
two
To
Too
filename.
147
083601-X Ch07.F
10/18/01
12:00 PM
Page 148
C#
SEARCH ARRAYS
SEARCH ARRAYS
Properties
083601-X Ch07.F
10/18/01
12:00 PM
Page 149
USING ARRAYS
RESULT:
The last occurrence of Five is at index 2.
filename.
149
083601-X Ch07.F
10/18/01
12:00 PM
Page 150
C#
083601-X Ch07.F
10/18/01
12:00 PM
Page 151
USING ARRAYS
Like an array, you can use the foreach statement for iterating
through a collections class. The following example acquires a
collection in a hashtable, a predefined collection class.
TYPE THIS:
RESULT:
using System;
using System.Collections;
public class Class1
{
public static void Main(string[] args)
{
Hashtable areacode = new Hashtable();
areacode.Add("209", "Stockton");
areacode Add("559", "Fresno");
areacode Add("916", "Sacramento");
foreach (string code in areacode.Keys)
{
Console.WriteLine(code + " " + areacode[code]);
}
}
}
209
559
916
Stockton
Fresno
Sacramento
filename.
151
083601-X Ch07.F
10/18/01
12:00 PM
Page 152
C#
PROGRAM STRUCTS
PROGRAM STRUCTS
values.
083601-X Ch07.F
10/18/01
12:00 PM
Page 153
USING ARRAYS
RESULT:
Using System;
[StructLayout(LayoutKind.Union)]
struct Union
{z
// Add struct information here.
}
filename.
153
083601-X Ch07.F
10/18/01
12:00 PM
Page 154
C#
ADD AN INDEXER
n indexer gives your class the ability to behave as
an array. If you have a class with many elements,
then an indexer lets you sort that information so
your program can get the element it needs from your class.
The set accessor sets the value of the accessor type. The
get and set accessors use the same access modifiers as
the indexer declaration itself; the access modifiers for get
and set must be as accessible as the indexer itself.
ADD AN INDEXER
Click Add.
Click Add Indexer.
083601-X Ch07.F
10/18/01
12:00 PM
Page 155
USING ARRAYS
int
TYPE THIS:
RESULT:
using System;
class Indexer
{
private int [] Array1 = new int[20];
public int this [int Index]
{
get
{
if (index < 0 | | index >= 20)
return 0;
}
set
{
if (!(index < 0 | | index >= 20))
Array1[index] = amount;
}
}
public int [] Array2 = new int[50];
public int this [int Index]
int Parameter1
window appears.
Click Add.
Click Finish.
155
083601-X Ch07.F
10/18/01
12:00 PM
Page 156
C#
INCLUDE ENUMERATIONS
INCLUDE ENUMERATIONS
Properties
156
083601-X Ch07.F
10/18/01
12:00 PM
Page 157
USING ARRAYS
RESULT:
using System;
public class Convert;
{
enum SpringMonths {Mar=1, Apr, May, Jun};
March = 1
filename.
157
093601-X Ch08.F
10/18/01
12:01 PM
Page 158
C#
LiteralsAndVariables.
158
093601-X Ch08.F
10/18/01
12:01 PM
Page 159
APPLIED FORMATTING
\'
Single quote
\"
Double-quote
\\
Backslash
\0
Null
\a
Alert
\b
Backspace
\f
Form feed
\n
New line
\r
Carriage return
\t
Horizontal tab
\u and \U
Unicode-escape-sequence *
\x
Hexadecimal-escape-sequence
159
093601-X Ch08.F
10/18/01
12:01 PM
Page 160
C#
AssignmentAndLength.
160
093601-X Ch08.F
10/18/01
12:01 PM
Page 161
RESULT:
using System;
namespace StringSample
{
class AssignmentAndLength
{
static void Main()
{
String sSpacesCount = "
6789";
int iSpacesCount = sSpacesCount.Length;
C:\>csc AssignStrings_ai.cs
C:\> AssignStrings_ai.exe
The greeting:
6789
is 9 characters long.
C:\>
Console.WriteLine (
"The greeting: \n{0}\nis {1} characters long.",
sSpacesCount, iSpacesCount);
}
}
}
161
093601-X Ch08.F
10/18/01
12:01 PM
Page 162
C#
CONCATENATE STRINGS
You can also use the Concat method on the String class
to perform concatenation. With this method, you can
concatenate one or more String classes together and get
a new String returned to you. Another overloaded
implementation of the String Class allows you to pass a
string array, which is handy if you have many strings to
concatenate into one representative string.
CONCATENATE STRINGS
Concatenate.
162
093601-X Ch08.F
10/18/01
12:01 PM
Page 163
TYPE THIS:
using System;
using System.Text;
namespace StringSample
{
class Concatenate
{
static void Main()
{
StringBuilder sbPersonalGreeting =
new StringBuilder("Hello, how are you today");
sbPersonalGreeting.Insert(0,"Danny - ");
sbPersonalGreeting.Append("?");
Console.WriteLine(sbPersonalGreeting);
}
}
}
A message appears
163
093601-X Ch08.F
10/18/01
12:01 PM
Page 164
C#
COMPARE STRINGS
omparing strings in code is useful when performing
logical operations. String comparisons are useful in
expressions that are used for an if or switch
statement. For example, you can use a string comparison
when someone is logging onto your Web site. You can
compare the password that the user entered to the
password in the database.
COMPARE STRINGS
Compare.
164
093601-X Ch08.F
10/18/01
12:01 PM
Page 165
TYPE THIS:
using System;
namespace StringSample
{
class Compare
{
static void Main()
{
Console.WriteLine("Please enter your password " +
"to enter the specified Photo Gallery:");
C:\>csc CompareStrings.cs
C:\> CompareStrings.exe
Please enter your password to
enter the specified Photo
Gallery.
Opensaysme
You can view the photos.
c:\>
opensaysme.
165
093601-X Ch08.F
10/18/01
12:01 PM
Page 166
C#
If you are just looking for a specific character, you can use
the IndexOf and LastIndexOf method of the String
class to see what index position contains that character.
Another useful way to find substrings is to use regular
expressions. This is a more sophisticated way to determine
if a substring exists. With regular expressions, you can go
further than substrings and look for patterns that exist in
the string.
Another handy string-comparison method is the EndsWith
method. You can use EndsWith to identify the extension of
a file and determine if code should run or not.
Search.
166
093601-X Ch08.F
10/18/01
12:01 PM
Page 167
Regular expressions are a very powerful way to find substrings or patterns in a string.
If you are trying to accomplish a complicated search of a string, use regular
expressions.
RESULT:
TYPE THIS:
using System;
using System.Text.RegularExpressions;
namespace StringSample
{
class Search
{
static void Main()
{
string[] sFileNames = new string[3] {
"allphotos.aspx",
"lri_familyreunion_jan2001_001.jpg",
"hri_familyreunion_jan2001_001.jpg"};
Regex rePictureFile = new Regex(".jpg");
C:\>csc SearchSubStrings_ai.cs
C:\> SearchSubStrings_ai.exe
lri_familyreunion_jan2001_001.jpg
is a photo file.
hri_familyreunion_jan2001_001.jpg
is a photo file.
C:\>
A message appears
167
093601-X Ch08.F
10/18/01
12:01 PM
Page 168
C#
REPLACE CHARACTERS
REPLACE CHARACTERS
Replace.
168
093601-X Ch08.F
10/18/01
12:01 PM
Page 169
169
093601-X Ch08.F
10/18/01
12:01 PM
Page 170
C#
EXTRACT SUBSTRINGS
EXTRACT SUBSTRINGS
Extract.
170
093601-X Ch08.F
10/18/01
12:01 PM
Page 171
TYPE THIS:
using System;
namespace StringSample
{ class Extract
{ static void Main(string[] args)
{ string sPhoto = "src_fmlyreunion_jan2001_001.jpg";
string sFilePrefix;
string sBasePhoto =sPhoto.Substring(4);
Console.WriteLine(sBasePhoto);
Console.WriteLine("Please choose format to view?");
Console.WriteLine("[0]Low Resolution");
Console.WriteLine("[1]High Resolution");
Console.Write("?: ");
string sSelection = Console.ReadLine();
switch (sSelection)
{ case "0" :
sFilePrefix = "lri_"; break;
case "1" :
sFilePrefix = "hri_"; break;
default :
sFilePrefix = "src_"; break;}
string sFullFile = sFilePrefix + sBasePhoto;
Console.WriteLine("You will view {0}", sFullFile);
C:\>csc ExtractSubstrings_ai.cs
C:\> ExtractSubstrings_ai.exe
fmlyreunion_jan2001_001.jpg
Please choose format to view?
[0]Low Resolution
[1]High Resolution
?: 1
You will view hri_fmlyreunion_
jan2001_001.jpg
C:\>
}}}
A message appears
console.
171
093601-X Ch08.F
10/18/01
12:01 PM
Page 172
C#
CharacterCase.
172
093601-X Ch08.F
10/18/01
12:01 PM
Page 173
RESULT:
using System;
namespace StringSample
{ class InitialCaps
{ static void Main()
{ string sFullName = "joE mARkiewiCz";
string [] sNameParts =
sFullName.Split(char.Parse(" "));
string [] sNewParts = new string[2];
int iCount = 0;
foreach (string sPart in sNameParts)
{
sNewParts[iCount] =
sPart[0].ToString().ToUpper() +
sPart.Substring(
1,(sPart.Length - 1)).ToLower();
iCount++;
}
string sNewFullName = String.Join(" ",sNewParts);
C:\>csc
ChangeCase_ai.cs
C:\>
ChangeCase_ai.exe
Applying the custom
intitial caps
formatting on 'joE
mARkiewiCz'
gives the following
result: Joe
Markiewicz
C:\>
A welcome message
appears in upper case.
173
093601-X Ch08.F
10/18/01
12:01 PM
Page 174
C#
TRIM SPACES
TRIM SPACES
TrimSpaces.
174
093601-X Ch08.F
10/18/01
12:01 PM
Page 175
Trimming strings for more than white space can enable you
to strip any other unwanted characters like punctuation.
RESULT:
TYPE THIS:
using System;
namespace StringSample
{
/// <summary>
/// The Trim can accept an array of unicode chars that
/// will be used to trim from either end of the string.
/// Note that it does not matter what order the chars
/// are set.
/// </summary>
class TrimSpaces
{
static void Main()
{
String sGreeting =
" Welcome to My Shared Photo Album! " ;
C:\>csc TrimSpaces_ai.cs
C:\> TrimSpaces_ai.exe
Welcome to My Shared Photo Album
C:\>
Console.Write(sGreeting.Trim(
char.Parse(" "), char.Parse("!")));
}
}
}
175
093601-X Ch08.F
10/18/01
12:01 PM
Page 176
C#
REMOVE CHARACTERS
REMOVE CHARACTERS
RemoveCharacters.
176
093601-X Ch08.F
10/18/01
12:01 PM
Page 177
TYPE THIS:
using System;
namespace StringSample
{
class RemoveCharacters
{
static void Main(string[] args)
{
string sUsersFullName = "Austin Joseph Ryan";
C:\>csc RemoveCharacters_ai.cs
C:\> RemoveCharacters_ai.exe
Austin Ryan
C:\>
177
093601-X Ch08.F
10/18/01
12:01 PM
Page 178
C#
SPLIT A STRING
SPLIT A STRING
Split.
178
093601-X Ch08.F
10/18/01
12:01 PM
Page 179
C:\>csc SplitString_ai.cs
C:\> SplitString_ai.exe
The high resolution image selected
was index 001 of pictures at
disney which was taken jan2001.
C:\>
switch (sFileParts[0]) {
case "hri" :
sPhotoType = "high resolution image"; break;
case "tni" :
sPhotoType = "thumbnail image"; break;
default :
sPhotoType = "unknown image type"; break;
}
Console.WriteLine("The " + sPhotoType + " selected was "
+ "index " + sPhotoIndex + " of pictures at "
+ sPhotoEvent + " which was taken "
+ sPhotoDate + ".");
}
A message appears,
179
093601-X Ch08.F
10/18/01
12:01 PM
Page 180
C#
JOIN STRINGS
JOIN STRINGS
Join.
180
093601-X Ch08.F
10/18/01
12:01 PM
Page 181
TYPE THIS:
using System;
using System.Globalization;
namespace StringSample
{
class WeekDays
{
static void Main()
{
string [] sDaysOfTheWeek = new string[7];
DateTimeFormatInfo dtfInfo =
new DateTimeFormatInfo();
sDaysOfTheWeek = dtfInfo.DayNames;
string sWeekDays = String.Join
(", ",sDaysOfTheWeek,1,5 );
Console.WriteLine
("The week days are: " + sWeekDays);
}
}
}
C:\>csc JoinStrings_ai.cs
C:\> JoinStrings_ai.exe
The week days are: Monday, Tuesday,
Wednesday, Thursday, Friday
C:\>
181
093601-X Ch08.F
10/18/01
12:01 PM
Page 182
C#
PAD STRINGS
PAD STRINGS
Pad.
182
093601-X Ch08.F
10/18/01
12:01 PM
Page 183
TYPE THIS:
using System;
namespace StringSample
{
/// <summary>
/// Take the same Greeting and pad with a '-' instead of
/// a space. Do this with taking the string length plus
/// padding amount.
/// </summary>
class Pad {
static void Main()
{ string sGreeting =
"Welcome to 'My Personal Photo Album'";
string sGreetingPadded;
C:\>csc PadStrings_ai.cs
C:\> PadStrings_ai.exe
--- Welcome to 'My Personal
Photo Album'--C:\>
sGreetingPadded = sGreeting.PadLeft
((sGreeting.Length + 5),char.Parse("-"));
sGreetingPadded = sGreetingPadded.PadRight
((sGreetingPadded.Length + 5),char.Parse("-"));
Console.WriteLine(sGreetingPadded);
}
}
}
183
103601-X Ch09.F
10/18/01
12:01 PM
Page 184
C#
ution Explo...
Solution Explo...
184
Click Help.
Click Index.
103601-X Ch09.F
10/18/01
12:01 PM
Page 185
ACCESSING PROPERTIES
185
103601-X Ch09.F
10/18/01
12:01 PM
Page 186
C#
ution Explo...
Solution Explo...
186
Click Help.
Click Index.
103601-X Ch09.F
10/18/01
12:01 PM
Page 187
ACCESSING PROPERTIES
Index
Click comparison
between properties and
accessors under properties in
the topics list.
187
103601-X Ch09.F
10/18/01
12:01 PM
Page 188
C#
The set accessor acts much like a method with the void
return type. The body of a set accessor provides a new
value for the property. A set accessor must include a return
type, but unlike the get accessor, that return type must not
include an expression.
After the get accessor retrieves the value, it must return the
value with the return or throw statement. All return
Solution Explo...
188
103601-X Ch09.F
10/18/01
12:01 PM
Page 189
ACCESSING PROPERTIES
TYPE THIS:
using System;
class Test;
{
abstract int Area
{get;
set;
}
class Cube: Area
{
public int side;
public Cube(int s)
{side = x;
}
public override int Area
{get
{
return side * side;
}
set
{side = Math.Sqrt(value);
}}}
Right-click Class1.
Click Add.
)
next to the {} Method name.
189
103601-X Ch09.F
10/18/01
12:01 PM
Page 190
C#
You can access the C# Property Wizard via the Class View
window. The Property Wizard contains all the basic building
blocks of a property including the get and set accessors.
When you finish entering the accessors and all other
property information in the Property Wizard, the basic get
and/or set accessor skeletons appear so that you can add
arguments into the skeletons.
int
int
public
int
Click to select a
property access modifier from
the drop-down list.
190
103601-X Ch09.F
10/18/01
12:01 PM
Page 191
ACCESSING PROPERTIES
RESULT:
using System;
class Return;
private string name;
public string Name
{
get
{
}
}
Click Finish.
191
103601-X Ch09.F
10/18/01
12:01 PM
Page 192
C#
192
103601-X Ch09.F
10/18/01
12:01 PM
Page 193
ACCESSING PROPERTIES
193
103601-X Ch09.F
10/18/01
12:01 PM
Page 194
C#
Point
Click OK.
194
next
next
Right-click Interface1.
Click Add.
Click Add Property.
103601-X Ch09.F
10/18/01
12:01 PM
Page 195
ACCESSING PROPERTIES
TYPE THIS:
interface Clones
{
object Clone();
}
interface Compare
{
int CompareTo(object template);
}
class Assembly: Clones, Compare
{
int Compare.CompareTo(object template);
}
Click
to select the
property type from the
drop-down list.
Click Finish.
195
113601-X Ch10.F
10/18/01
12:01 PM
Page 196
C#
196
Click Help.
Click Index.
113601-X Ch10.F
10/18/01
12:02 PM
Page 197
BUILDING FORMS
appears.
10
The Introduction to
Click
to select Visual C#
in the Filtered by drop-down
list.
197
113601-X Ch10.F
10/18/01
12:02 PM
Page 198
C#
When you view the form for the first time, you will notice
that the form has dots throughout the form. These dots
represent the grid, and you can use these dots as
boundaries for objects that you add to the form. The
gridlines help ensure that all the objects in your form look
pleasing to the eye and that form objects do not interlap.
The form appears in the parent window so you can edit its
properties and add information to the form. Form
properties appear in the Properties window. If you add a
new form in the Windows Form Designer, then the new
form will appear in its own window with its own name.
198
Right-click FormOne in
Click Add.
113601-X Ch10.F
10/18/01
12:02 PM
Page 199
BUILDING FORMS
10
Form2.cs
Click Open.
199
113601-X Ch10.F
10/18/01
12:02 PM
Page 200
C#
200
Right-click FormTwo in
Click Add.
113601-X Ch10.F
10/18/01
12:02 PM
Page 201
BUILDING FORMS
10
RESULT:
using
using
using
using
using
using
System;
System.Drawing;
System.Collections;
System.ComponentModel;
System.Windows.Forms;
System.Data;
namespace MyFormProgram
{
public class Form1 : System.Windows.Forms.Form
// Enter rest of your form here.
Form1
FormTwo
Form2.cs
Click Open.
Click OK.
window appears.
201
113601-X Ch10.F
10/18/01
12:02 PM
Page 202
C#
202
Right-click FormStart in
Click Properties.
113601-X Ch10.F
10/18/01
12:02 PM
Page 203
BUILDING FORMS
10
TYPE THIS:
csc class1.cs class2.cs /main:Class2
Click
Click OK.
203
113601-X Ch10.F
10/18/01
12:02 PM
Page 204
C#
204
Click to select
Click OK.
113601-X Ch10.F
10/18/01
12:02 PM
Page 205
BUILDING FORMS
10
TYPE THIS:
frmAbout MyForm = new frmAbout();
MyForm.ShowDialog( this );
drop-down list.
pressing F5.
Alt+F4.
Click
value.
filename.
205
113601-X Ch10.F
10/18/01
12:02 PM
Page 206
C#
LAYOUT A FORM
LAYOUT A FORM
206
Click View.
Click Toolbox.
113601-X Ch10.F
10/18/01
12:02 PM
Page 207
BUILDING FORMS
10
to the form.
CONTINUED
207
113601-X Ch10.F
10/18/01
12:02 PM
Page 208
C#
LAYOUT A FORM
hen you design your form you can add various
controls from the Toolbox. Controls are buttons,
text boxes, checkboxes, radio buttons, and other
features that let the user manipulate data in the form and
send that data back to the program.
hold down your left mouse button, and move the form
accordingly. The mouse pointer turns from an arrow into a
two-sided arrow when you resize it. For example, if you
move the bottom center handle you can raise the height of
the form. If you have controls, such as buttons, then they
will resize automatically when you resize your form.
The dots in the form represent the form grid that acts as a
guide for placing your controls. No matter where you place
the controls on the form, the button will move the control
to the nearest grid point.
208
113601-X Ch10.F
10/18/01
12:02 PM
Page 209
BUILDING FORMS
10
RESULT:
to the form.
209
113601-X Ch10.F
10/18/01
12:02 PM
Page 210
C#
210
Click
beside the
StartPosition entry
(WindowsDefault Location).
113601-X Ch10.F
10/18/01
12:02 PM
Page 211
BUILDING FORMS
10
TYPE THIS:
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container()
this.Size = new System.Drawing.Size(100,100);
this.Text = "MyForm";
this.Location = new System.Drawing.Point(15,15);
}
Click to select
CenterScreen from
the drop-down list.
211
113601-X Ch10.F
10/18/01
12:02 PM
Page 212
C#
212
113601-X Ch10.F
10/18/01
12:02 PM
Page 213
BUILDING FORMS
10
TYPE THIS:
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container()
this.Size = new System.Drawing.Size(100,100);
this.Text = "MyForm";
this.MaximumSize = new System.Drawing.Size(400,400);
}
Text
window.
Type NewForm.
Press Enter.
Your new form name
213
113601-X Ch10.F
10/18/01
12:02 PM
Page 214
C#
214
window.
113601-X Ch10.F
10/18/01
12:02 PM
Page 215
BUILDING FORMS
10
TYPE THIS:
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container()
this.Size = new System.Drawing.Size(100,100);
this.Text = "MyForm";
this.Opacity = 0.8;
}
Opacity
percentage appears in
bold type.
215
123601-X Ch11.F
10/18/01
12:02 PM
Page 216
C#
AN INTRODUCTION TO WEB
FORMS AND CONTROLS
The Net Platform
The .NET platform provides the ASP.NET Framework for
building user interfaces for Web applications. Even
though ASP.NET is a totally new framework, you may
find ASP.NET applications easy to develop due to many
of the transferable skills that come from development
with ASP applications. ASP.NET runs on the same
platform that ASP applications run on today, Windows
2000 and Internet Information Server (IIS) 5.0. ASP.NET
applications uses Web Forms as the primary file type,
which have an extension of .aspx. IIS processes this
216
123601-X Ch11.F
10/18/01
12:02 PM
Page 217
11
Web Forms
Web Forms are the primary file type used in ASP.NET to
create Web pages. Web Forms have an extension of .aspx.
These pages are the next generation pages to ASP pages
that are created in ASP applications. Web Forms are more
217
123601-X Ch11.F
10/18/01
12:02 PM
Page 218
C#
appears.
Web application.
Click
218
to select
http://localhost for
your location.
Click OK.
123601-X Ch11.F
10/18/01
12:02 PM
Page 219
11
TYPE THIS:
<%@ Page Trace="true" %>
RESULT:
The Request Details, Trace
Information, Cookies
Collection, Headers
Collection, and Server
Variables are displayed at the
bottom of your aspx page in
the form of tables.
VisualCSharpBlueprint
http://localhost. You
can use this project to create
a Web site.
219
123601-X Ch11.F
10/18/01
12:02 PM
Page 220
C#
VisualCSharpBlueprint
Click Open.
to select a Category.
220
123601-X Ch11.F
10/18/01
12:02 PM
Page 221
11
When developing Web Forms, you can implement server-side code in two ways. The first
implementation, well supported in VS .NET, involves creating an additional code-behind page containing
an extension of .cs. The second implementation is embedding a server-side <script> tag.
Example:
<html>
<script language="C#" runat="server">
void Submit_Click(object sender, EventArgs e) {
if (txtName.Value == "RobertPhillips" &
txtPwd.Value == "pharmacist")
spnMessage.InnerHtml = "You are authenticated!";
else
spnMessage.InnerHtml = "Login Failed!";
}
</script>
<body> <form method=post runat=server>
<h3>Enter Name: <input id="txtName" type=text size=40 runat=server>
<h3>Enter Password: <input id="txtPwd" type=password size=40 runat=server>
<input type=submit value="Enter" OnServerClick="Submit_Click" runat=server>
<h1><span id="spnMessage" runat=server> </span></h1>
</form></body></html>
CreateWebForm.aspx
221
123601-X Ch11.F
10/18/01
12:02 PM
Page 222
C#
Toolbox
Double-click Button in
222
the Toolbox.
form.
123601-X Ch11.F
10/18/01
12:02 PM
Page 223
11
RESULT:
Properties
Text
appears.
Web page.
223
123601-X Ch11.F
10/18/01
12:02 PM
Page 224
C#
RESPOND TO AN EVENT IN
SERVER-SIDE CONTROLS
ou can implement event handlers to respond to user
interaction with your Web Form. Some common
events available to program are mouse clicks on
buttons, or the mouse moving over text. Using event
handlers, a common object-oriented programming practice,
creates a more efficient programming model. This model
only executes code when the corresponding event fires for
the handler. Without this model, you must use procedural
style coding, which evaluates code from top to bottom and
requires you to run code to determine if you should call a
procedure.
server control.
224
123601-X Ch11.F
10/18/01
12:02 PM
Page 225
11
You can create a code-behind page that responds to an event using the following bare bones of
implementation. This is hand-crafted code and not the automatically generated code that comes from
the VS .NET environment. You first create the .aspx page RespondToEvent_ai.aspx with the first
block of code. Next, you create the supporting code-behind page, RespondToEvent_ai.aspx.cs.
You then place both of these files into an existing ASP.NET site to receive the results into the Web page.
TYPE THIS:
RESULT:
TYPE THIS:
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
public class RespondToEvent_ai : Page {
public Label lblGreeting;
public void Page_Load(object Source, EventArgs e) {
lblGreeting.Text="Welcome to MySharePhotoAlbum.com";
}
}
The Button1_Click
function is created.
Web page.
Type Label1.Text =
Button1_Click function
to update the label when the
button is clicked.
225
123601-X Ch11.F
10/18/01
12:02 PM
Page 226
C#
Add a DropDownList
226
123601-X Ch11.F
10/18/01
12:02 PM
Page 227
11
RESULT:
227
123601-X Ch11.F
10/18/01
12:02 PM
Page 228
C#
Toolbox
228
Create a variable of
123601-X Ch11.F
10/18/01
12:02 PM
Page 229
11
TYPE THIS:
<%@ Page language="c#"%>
<html>
<head>
</head>
<body>
<form method="post" runat="server">
<%
HttpRequest oRequest;
oRequest = this.Request;
Web page.
ListBox.
229
133601-X Ch12.F
10/18/01
12:02 PM
Page 230
C#
The SQL Server .NET Data Provider classes come from the
System.Data.SqlClient namespace. The SQL Server
.NET Data Provider uses its own protocol to communicate
with SQL Server. The provider is lightweight and performs
well, accessing a SQL Server data source directly without
adding an OLE DB or Open Database Connectivity (ODBC)
layer. When you need to work with other database besides
Microsoft SQL Server, you should use the OLE DB .NET
Data Provider, which you can find in the
System.Data.OleDb namespace.
CONNECTION
Connections are the starting point to your data access and determine how you connect to the data store. You need
to set properties, like ConnectionString, to establish communications to your data store.
SQLCONNECTION KEY PROPERTIES AND METHODS
PROPERTY
DESCRIPTION
ConnectionString
ConnectionTimeout
Database
DataSource
ServerVersion
(read) string that identifies version of the connected SQL Server instance
State
METHOD
DESCRIPTION
BeginTransaction
ChangeDatabase
Close
CreateCommand
SqlConnection
Open
ConnectionString
230
133601-X Ch12.F
10/18/01
12:02 PM
Page 231
12
ADO.NET commands are important for stored procedures and running SQL Statements.
SQLCOMMAND KEY PROPERTIES AND METHODS
PROPERTY
DESCRIPTION
CommandText
(read/write) the T-SQL statement or stored procedure to execute at the data source
CommandTimeout
CommandType
Connection
Parameters
Transaction
METHOD
DESCRIPTION
Cancel
CreateParameter
ExecuteNonQuery
executes a T-SQL statement against the connection and returns the number of
rows affected
ExecuteReader
ExecuteScalar
executes the query, and returns the first column of the first row in the resultset
returned by the query
ExecuteXmlReader
Prepare
DATA ADAPTER
A DataAdapter is the object that bridges between the source data and the DataSet object so retrieve and
updates can occur.
DATAADAPTER KEY PROPERTIES AND METHODS
PROPERTY
DESCRIPTION
AcceptChangesDuringFill
TableMappings
(read) a collection that provides the master mapping between a source table and a
DataTable
METHOD
DESCRIPTION
Fill
adds or refreshes rows in the DataSet to match those in the data source using
the DataSet name, and creates a DataTable named "Table"
FillSchema
adds a DataTable named "Table" to the specified DataSet and configures the
schema to match that in the data source based on the specified SchemaType
GetFillParameters
retrieves the parameters set by the user when executing a SQL select statement
Update
Calls the respective insert, update, or delete statements for respective action
in the specified DataSet from a DataTable named "Table"
231
133601-X Ch12.F
10/18/01
12:02 PM
Page 232
C#
232
Add a SqlConnection
variable and initialize with a
valid connection string to
your database.
Add a SqlDataAdapter
variable and initialize with a
valid select statement.
133601-X Ch12.F
10/18/01
12:02 PM
Page 233
12
TYPE THIS:
<SCRIPT language="C#" runat="server">
void Page_Load(object sender, System.EventArgs e){
if (!IsPostBack)
BindData(); }
void Grid_Change(Object sender,
DataGridPageChangedEventArgs e){
dgdTitles.CurrentPageIndex = e.NewPageIndex;
BindData(); }
void BindData() {
SqlConnection cnPubs = new SqlConnection(
"server=(local);uid=sa;pwd=;database=pubs");
SqlDataAdapter daTitles = new SqlDataAdapter(
"select title, notes, price, pubdate "
+ "from titles", cnPubs);
DataSet dsTitles = new DataSet();
daTitles.Fill(dsTitles, "titles");
dgdTitles.DataSource=
dsTitles.Tables["titles"].DefaultView;
dgdTitles.DataBind(); }
</SCRIPT>
233
133601-X Ch12.F
10/18/01
12:02 PM
Page 234
C#
Autoformat
3601-X fg1205_06.eps
234
133601-X Ch12.F
10/18/01
12:02 PM
Page 235
12
Example:
string SortExpression = "";
void Grid_Change(Object sender,
DataGridPageChangedEventArgs e) {
dgdTitles.CurrentPageIndex = e.NewPageIndex;
BindData(); }
void Sort_Grid(Object sender,
DataGridSortCommandEventArgs e) {
SortExpression = e.SortExpression.ToString();
BindData(); }
void BindData() {
if (SortExpression == "")
SortExpression = "title";
SqlConnection cnPubs = new SqlConnection(
"server=(local);uid=sa;pwd=;database=pubs");
SqlDataAdapter daTitles = new SqlDataAdapter(
"select title, notes, price, pubdate from "
+ "titles order by " + SortExpression,
cnPubs);
// Use this Data Adapter for rebinding. }
Professional 1
appears.
Web page.
235
133601-X Ch12.F
10/18/01
12:02 PM
Page 236
C#
to DataAccess.
236
133601-X Ch12.F
10/18/01
12:02 PM
Page 237
12
Example:
//
//
//
//
Add a SqlCommand
Open a connection,
237
133601-X Ch12.F
10/18/01
12:02 PM
Page 238
C#
to DataAccess.
238
133601-X Ch12.F
10/18/01
12:02 PM
Page 239
12
RESULT:
C:\>csc UpdateData_ai.cs
C:\> UpdateData_ai.exe
You ran the following SQL Statement:
UPDATE authors SET zip = 30004 WHERE
au_id = '172-32-1176'
Do you want to commit the change?
[Y/N] Y
C:\>
Add a SqlCommand
Open a connection,
execute the query, and close
the connection.
239
133601-X Ch12.F
10/18/01
12:02 PM
Page 240
C#
to DataAccess.
240
133601-X Ch12.F
10/18/01
12:02 PM
Page 241
12
3601-X fg1219_20.eps
Add a SqlCommand
Open a connection,
241
133601-X Ch12.F
10/18/01
12:02 PM
Page 242
C#
If all your data access is put into stored procedures, you can
remove direct access to your tables. Stored procedures give
you known entry points to your data. If you keep read,
update, and delete access enabled on your tables, you
cannot protect your data from harmful modification,
whether intentional or unintentional.
System.Data,
System.Data.SqlTypes,
and
System.Data.SqlClient
namespaces.
242
SqlConnection variable.
Add a SqlParameter
variable by setting the
properties, including the
ParameterName,
SqlDbType, Direction,
and Value.
133601-X Ch12.F
10/18/01
12:02 PM
Page 243
12
Add a SqlDataReader
variable and use the
ExecuteReader to run the
stored procedure.
connection.
A message appears
243
143601-X Ch13.F
10/18/01
12:03 PM
Page 244
C#
to XMLSamples.
244
to ReadXML.
XmlTextReader variable
and initialize with null.
Create a new
XmlTextReader variable
and initialize with the name
of the XML file.
143601-X Ch13.F
10/18/01
12:03 PM
Page 245
13
The following is an example that reads the XML with a StringReader and evaluates
several node types. The output documents the nodes that are detected and writes
out the node name, type, and value.
Example:
while (reader.Read() {
switch (reader.NodeType) {
case XmlNodeType.ProcessingInstruction:
OutputXML (reader, "ProcessingInstruction"); break;
case XmlNodeType.DocumentType:
OutputXML (reader, "DocumentType"); break;
case XmlNodeType.Comment:
OutputXML (reader, "Comment"); break;
case XmlNodeType.Element:
OutputXML (reader, "Element");
while(reader.MoveToNextAttribute())
OutputXML (reader, "Attribute");
break;
case XmlNodeType.Text:
OutputXML (reader, "Text"); break;
case XmlNodeType.Whitespace:
break;
}}
245
143601-X Ch13.F
10/18/01
12:03 PM
Page 246
C#
to XMLSamples.
246
143601-X Ch13.F
10/18/01
12:03 PM
Page 247
13
TYPE THIS:
using System; using System.IO; using System.Xml;
public class Sample
{ public static void Main()
{ XmlDocument doc = new XmlDocument();
string sXML =
@""<?xml version=""1.0"" standalone=""no""?>
<!This file represents a list of favorite photos>
<photofavorites owner=""Frank Ryan"">
<photo cat=""vacation"" date=""2000"">
<title>Maddie with Minnie</title>
</photo>
</photofavorites>"; // end of string
doc.LoadXml(sXML);
doc.Save("data.xml");
}}
the WriteStartElement
method.
Add an attribute to
the element.
247
143601-X Ch13.F
10/18/01
12:03 PM
Page 248
C#
to XMLSamples.
248
Create a new
XPathNavigator using the
XPathDocument created.
Create an
XPathNodeIterator
variable that will contain the
result of running an XPath
query that returns all of the
photo/title elements.
143601-X Ch13.F
10/18/01
12:03 PM
Page 249
13
You can use the recursive decent operator to search for an element at
any depth. Make sure that the source XML document,
photo_library.xml, is in the working directory of the EXE file.
TYPE THIS:
using System; using System.IO; using System.Xml; using System.Xml.XPath;
namespace XMLSamples {
public class XMLwithXPath {
private const String sXMLDocument = "photo_library.xml";
public static void Main() {
Console.WriteLine ("XPath query results are:");
XPathDocument xpdPhotoLibrary = new XPathDocument(sXMLDocument);
XPathNavigator xpnPhotoLibrary = xpdPhotoLibrary.CreateNavigator();
XPathNodeIterator xpniPhotoLibrary =
xpnPhotoLibrary.Select ("//photo/title");
while (xpniPhotoLibrary.MoveNext())
Console.WriteLine(xpniPhotoLibrary.Current.Name
+ " = " + xpniPhotoLibrary.Current.Value);
}}}
RESULT:
XPath query results are:
title = Fun at the Beach
title = Opening the gifts
249
143601-X Ch13.F
10/18/01
12:03 PM
Page 250
C#
to ApplyXSL.
250
143601-X Ch13.F
10/18/01
12:03 PM
Page 251
13
RESULT:
C:\>csc ApplyXSL_ai.cs
C:\> ApplyXSL_ai.exe
"Screen will echo out the nodes in the document.
Including the type node, name, and contents."
C:\>
251
153601-X Ch14.F
10/18/01
12:03 PM
Page 252
C#
INTRODUCTION TO DISTRIBUTED
APPLICATIONS
he .NET Framework is Microsofts new computing
platform designed to simplify application development
in the highly distributed environment of the Internet.
Microsoft has put a major effort in revamping the
architecture for their component-based solutions. When
you create applications on the .NET platform, you find
component development tightly integrated with the
solutions you build.
DLL HELL
252
153601-X Ch14.F
10/18/01
12:03 PM
Page 253
14
253
153601-X Ch14.F
10/18/01
12:03 PM
Page 254
C#
CREATE AN ASSEMBLY
to Photo.
variables.
153601-X Ch14.F
10/18/01
12:03 PM
Page 255
Create a public
property for the Category.
14
Example:
using System;
namespace PhotoAlbum
{
public class Photo_ex{
public Photo(){
// Constructor logic goes here.
}
public string GetFullDescription() {
return "Catergory is " + Category +
" and title is " + Title +
" for the file " + FileName;
}
public string Category;
public string FileName;
public string Title;
}}
PhotoAlbum.
255
153601-X Ch14.F
10/18/01
12:03 PM
Page 256
C#
CREATE A CLIENT
Call the
to PhotoAlbum.
GetFullDescription
method to output the photos
properties to the console.
256
153601-X Ch14.F
10/18/01
12:03 PM
Page 257
14
Example:
namespace PhotoAlbum {
using System; using System.Collections;
public class Photos : IEnumerable {
private ArrayList phtList;
public Photos()
{ phtList = new ArrayList(); }
public void Add(Photo pht)
{ phtList.Add(pht); }
public void Remove(int phtRemove)
{ phtList.RemoveAt(phtRemove); }
public int Count
{ get{ return phtList.Count;} }
public IEnumerator GetEnumerator()
{ return phtList.GetEnumerator(); }
} }
PhotoAlbum.dll
Click Browse.
Click to select the
bin\Debug directory for the
server component created.
257
153601-X Ch14.F
10/18/01
12:03 PM
Page 258
C#
DEPLOY AN APPLICATION
PhotoAlbum.dll
Folder
Copy
New
Browse to a directory to
client.
258
153601-X Ch14.F
10/18/01
12:03 PM
Page 259
14
Example:
<configuration>
<runtime>
<assemblyBinding xmlns="urn:
schemas-microsoft-com:asm.v1">
probing privatePath=
"bin;binother\sub_bin "/>
<dependentAssembly>
<assemblyIdentity name=
"yourAssembly"
publickeytoken=
"23ab4ba49e0a69a1"
culture=en-us />
<bindingRedirect oldVersion=
"1.0.0.0"
newVersion="2.0.0.0"/>
</dependentAssembly>
/assemblyBinding>
</runtime>
</configuration>
Paste
created folder.
259
153601-X Ch14.F
10/18/01
12:03 PM
Page 260
C#
deployment directory.
of the assembly.
prompt.
Navigate to the
to create a key.
260
153601-X Ch14.F
10/18/01
12:03 PM
Page 261
14
the component.
CONTINUED
261
153601-X Ch14.F
10/18/01
12:03 PM
Page 262
C#
CREATE A CLIENT
Accessibility
262
1.0.0.0
C:\WINNT\Microsoft.NET\Fra...
Click Browse.
153601-X Ch14.F
10/18/01
12:03 PM
Page 263
14
TYPE THIS:
using System; using SharedPhotoAlbum;
namespace PhotoAlbumClient {
class Client{
static void Main(string[] args){
Photo myPhoto = new Photo(
"Vacation",
"src_christmas_dec-1998_01.jpg",
"Christmas in the Mountains");
Console.WriteLine(myPhoto.GetFullDescription());
} } }
SharedPhotoAlbum.dll
Copy Local
False
Click a component.
Click Open.
Click OK.
A message appears
assembly.
263
153601-X Ch14.F
10/18/01
12:03 PM
Page 264
C#
After the assembly is in the GAC, you can then run your
client. If you need to update the shared components, all you
need to do is copy over the existing component and the
client application will use that copy of the component the
next time it is called. If you have a new version of the
component that is not compatible with the currently
deployed component, you need to version it (see page 266).
In the application deployment described here, both
components and client application reside on the same
machine. Remoting components, on the other hand, is
much more involved and requires the use of a proxy.
DEPLOY AN APPLICATION
SharedPhotoAlbumClient.exe
SharedPhotoAlbum.dll
264
153601-X Ch14.F
10/18/01
12:03 PM
Page 265
14
RESULT:
Category is Vacation and title is Christmas in the Mountains for the file src_christmas_dec1998_01.jpg
SharedPhotoAlbum.dll
Run SharedPhoto
AlbumClient.exe.
A message appears
265
153601-X Ch14.F
10/18/01
12:03 PM
Page 266
C#
266
Open the
Change the
AssemblyInfo.cs file.
AssemblyVersion to a
later version number.
153601-X Ch14.F
10/18/01
12:03 PM
Page 267
14
267
153601-X Ch14.F
10/18/01
12:03 PM
Page 268
C#
Accessibility
268
Reference.
1.0.0.0
C:\WINNT\Microsoft.NET\Fra...
Click Browse.
153601-X Ch14.F
10/18/01
12:03 PM
Page 269
Click Open.
Click OK.
Press F5 to save, build, and
run the console application.
14
EXAMPLE:
<configuration>
<runtime>
<assemblyBinding
xmlns="urn:schemas-microsoftcom:asm.v1">
<dependentAssembly>
<assemblyIdentity name=
"VersionedPhotoAlbum"
publicKeyToken=
"e79f3eb79bb2bf0a"
culture=""/>
<bindingRedirect
oldVersion= "1.0.0.0"
newVersion="2.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
A message appears
269
153601-X Ch14.F
10/18/01
12:03 PM
Page 270
C#
Double-click Web
service.
to select
http://localhost
for the Location.
270
Click
Click OK.
153601-X Ch14.F
10/18/01
12:03 PM
Page 271
14
TYPE THIS:
using System.IO;
[WebMethod]
public string GetFavoritesList(int UserID) {
string sServerPath = Server.MapPath("");
// Here you could make a database call to get XML.
string sFilePath = sServerPath+ "\\" + "Favorites1.xml";
string sList = GetXMLAsString(sFilePath);
return sList;
}
private string GetXMLAsString(string XMLDocumentPath) {
FileStream fsFavorites = new FileStream
(XMLDocumentPath,FileMode.Open,FileAccess.Read);
StreamReader srFavorites = new
StreamReader(fsFavorites);
return srFavorites.ReadToEnd();
}
RESULT:
The xml string in favorites.xml is returned from the
WebMethod.
Click Invoke.
is loaded.
description is loaded.
271
153601-X Ch14.F
10/18/01
12:03 PM
Page 272
C#
References
Type a name.
In the Solution Explorer,
right-click the class file.
Click to select a location
Click OK.
272
153601-X Ch14.F
10/18/01
12:03 PM
Page 273
14
Heavily investing into the future of Web Services, one of Microsofts current
initiatives, HailStorm, addresses common programming needs such as personal
profile information and contacts. Below is a list of some of the HailStorm Services.
HAILSTORM SERVICES
myAddress
myProfile
myContacts
myLocation
myNotifications
myInbox
myCalendar
myDocuments
myApplicationSettings
Application settings
myFavoriteWebSites
myWallet
myDevices
myServices
myUsage
Click OK.
to HelloConsoleApplication.
console appears.
273
163601-X Ch15.F
10/18/01
12:03 PM
Page 274
C#
274
DESCRIPTION
HelpLink
Message
Source
StackTrace
TargetSite
163601-X Ch15.F
10/18/01
12:03 PM
Page 275
15
try
{
// Run code that has the potential to throw exceptions
}
catch (Exception e)
{
// Run code that will generically handle the caught exception
}
finally
{
// Run cleanup code (runs with or without exception occurring)
}
275
163601-X Ch15.F
10/18/01
12:03 PM
Page 276
C#
THROWING AN EXCEPTION
ou can pass error information back to a calling client
with exceptions. You raise exceptions by using the
throw statement. If this thrown exception is in a try
block, the execution passes to the appropriate catch block
(see page 280 for details). If the exception is not in a try
block, then exception is raised to the caller. If the caller has
not made the call with try/catch blocks, then the
exception is raised to the next caller on the stack until it is
handled or leaves the application unhandled (which is not a
good thing).
THROWING AN EXCEPTION
to ThrowException.
276
Add an if statement
that checks the withdrawal
against the balance and
throws an exception if the
withdrawal is greater than
the balance.
163601-X Ch15.F
10/18/01
12:03 PM
Page 277
15
TYPE THIS:
XmlTextReader reader = null;
string sXMLDocument = "photo_library.xml";
try
{
// This will attempt to read a missing document
reader = new XmlTextReader (sXMLDocument);
reader.Read();
}
catch (Exception e) {
throw new Exception
("Error, can not read " + sXMLDocument,e);
}
finally {
// Finished with XmlTextReader
if (reader != null)
reader.Close();
}
C:\>csc
ThrowException_ai.cs
C:\> ThrowException_ai.exe
"Exception is raised"
C:\>
277
163601-X Ch15.F
10/18/01
12:03 PM
Page 278
C#
to TryCatch.
278
163601-X Ch15.F
10/18/01
12:03 PM
Page 279
15
TYPE THIS:
using System; using System.IO;
namespace ExceptionHandling {
class TryCatch {
static void Main() {
string sTextFile = "somenonexistingtextfile.txt";
String sLine;
C:\>csc TryCatch_ai.cs
C:\> TryCatch_ai.exe
"Message for System.IO.
FileNotFoundException occurs"
C:\>
279
163601-X Ch15.F
10/18/01
12:03 PM
Page 280
C#
to TryCatch.
280
163601-X Ch15.F
10/18/01
12:03 PM
Page 281
15
Example:
Example:
// Sample 2 Essentially same as 1
catch (Exception e)
{
}
Example:
// Sample 3 - Rethrows exception e
catch (Exception e)
{
throw (e);
}
Example:
// Sample 5 Handles a specific
// error and all others go to the
// general catch statement
catch (StackOverflowException e)
{
}
catch (Exception e)
{
}
The FileNotFound
281
163601-X Ch15.F
10/18/01
12:03 PM
Page 282
C#
to ExceptionHandling.
to FinallyBlock.
282
163601-X Ch15.F
10/18/01
12:03 PM
Page 283
15
The FileNotFound
283
163601-X Ch15.F
10/18/01
12:03 PM
Page 284
C#
you can create an event log source which will give context
to the entries that you write to the Event Log (source name
for application and which log you want to write to
Application, Security, System, or a custom event log). With
that Event Log object you will call the WriteEntry method
to put entries into the event log. When writing errors to
the log, you will want to classify the severity of the error.
These severities will affect what icon and type classification
the error is given in the event viewer.
The task below will take you through the basic steps of
setting up and logging to an Event Log.
to LogErrors.
284
Add an if statement to
check for the existence of the
event log and set the
CreateEventSource
property.
Create a new EventLog
variable and set the Source
for the event log.
163601-X Ch15.F
10/18/01
12:03 PM
Page 285
15
You can control the severity for entries that you place
in the Application Error Log. After running this sample,
open the Event Viewer and note that each one has a
different severity and each severity has a different icon.
Example:
string
string
string
string
string
sLog = "Application";
sSource = "MySharedPhotoAlbum";
sErrorMsg1 = "Message for Information.";
sErrorMsg2 = "Message for Error.";
sErrorMsg3 = "Message for Warning.";
if ( !EventLog.SourceExists(sSource) ) {
EventLog.CreateEventSource(sSource,sLog); }
EventLog elMain = new EventLog();
elMain.Source = sSource;
if ( elMain.Log.ToUpper() != sLog.ToUpper() ){
Console.WriteLine
("Source is not available to use!");
return;}
elMain.WriteEntry(sErrorMsg1,EventLogEntryType.Information);
elMain.WriteEntry(sErrorMsg2,EventLogEntryType.Error);
elMain.WriteEntry(sErrorMsg3,EventLogEntryType.Warning);
Add an if statement to
write a message if some other
application is accessing
the log.
Add the WriteEntry
285
173601-X AppA.F
10/18/01
12:04 PM
Page 286
APPENDIX
BASIC EXAMPLES
DECLARING VARIABLES
Visual Basic
C#
JScript
Dim x As Integer
Dim x As Integer = 10
int x;
int x = 10;
var x : int;
var x : int = 10;
Visual Basic
C#
JScript
comment
x = 1
comment
Rem comment
// comment
/* multiline
comment */
// comment
/* multiline
comment */
Visual Basic
C#
JScript
nVal = 7
nVal = 7;
nVal = 7;
COMMENTS
ASSIGNMENT STATEMENTS
IF...ELSE STATEMENTS
Visual Basic
If nCnt <= nMax Then
nTotal += nCnt Same as nTotal = nTotal + nCnt
nCnt += 1
Same as nCnt = nCnt + 1
Else
nTotal += nCnt
nCnt -= 1
End If
C#
JScript
286
173601-X AppA.F
10/18/01
12:04 PM
Page 287
C# QUICK REFERENCE
CASE STATEMENTS
Visual Basic
Select Case n
Case 0
MsgBox ("Zero")
C#
JScript
switch(n) {
case 0:
MessageBox.Show("Zero");
break;
case 1:
MessageBox.Show("One");
break;
case 2:
MessageBox.Show("Two");
break;
default:
MessageBox.Show("?");
}
switch(n) {
case 0 :
MessageBox.Show("Zero");
break;
case 1 :
MessageBox.Show("One");
break;
case 2 :
MessageBox.Show("Two");
default :
MessageBox.Show("Default");
}
FOR LOOPS
Visual Basic
JScript
For n = 1 To 10
MsgBox("The number is " & n)
Next
For Each i In iArray
Box.Show(i)
Next i Msg
C#
for (int i = 1; i <= 10; i++)
MessageBox.Show("The number is {0}", i);
foreach (int i in iArray)
{
MessageBox.Show (i.ToString());
}
287
173601-X AppA.F
10/18/01
12:04 PM
Page 288
APPENDIX
BASIC EXAMPLES
WHILE LOOPS
Visual Basic
C#
JScript
Visual Basic
C#
// The method:
void ABC(int x)
{
...
}
// Calling the method:
ABC(i);
JScript
ABC(i,j);
Visual Basic
Public Sub ABC(ByRef y As Long) The parameter of ABC is declared by reference:
If ABC changes y, the changes are made to the value of x.
End Sub
ABC(x) Call the procedure
C#
// The method:
void ABC(ref int x)
{
...
}
// Calling the method:
ABC(ref i);
JScript
N/A (objects (including arrays) are passed by reference, but the object to which the variable refers to cannot be
changed in the caller). Properties and methods changed in the callee are visible to the caller.
/* Reference parameters are supported for external object, but not internal JScript functions */
comPlusObject.SomeMethod(&foo);
288
173601-X AppA.F
10/18/01
12:04 PM
Page 289
C# QUICK REFERENCE
Visual Basic
JScript
Try
try {
if (x == 0) {
throw new Error(513, "x equals zero");
}
else {
throw new Error(514, "x does not equal zero");
}
}
catch(e) {
Response.Write("Error number: " + e.number + "<BR>");
Response.Write("Error description: " + e.message + "<BR>");
}
finally {
Response.Write("Executing finally block.");
}
If x = 0 Then
Throw New Exception("x equals zero")
Else
Throw New Exception("x does not equal zero")
End If
Catch
MessageBox.Show("Error: " & Err.Description)
Finally
MessageBox.Show("Executing finally block.")
End Try
C#
// try-catch-finally
try
{
if (x == 0)
throw new System.Exception ("x equals zero");
else
throw new System.Exception ("x does not equal zero");
}
catch (System.Exception err)
{
System.Console.WriteLine(err.Message);
}
finally
{
System.Console.WriteLine("executing finally block");
}
Visual Basic
C#
JScript
o = Nothing
o = null;
o = null;
289
1873601-X AppB.F
10/18/01
12:04 PM
Page 290
APPENDIX
SYSTEM REQUIREMENTS
Program Versions
Shareware programs are fully functional, free trial versions
of copyrighted programs. If you like a particular program,
you can register with its author for a nominal fee and
receive licenses, enhanced versions, and technical support.
Freeware programs are free, copyrighted games,
applications, and utilities. You can copy them to as many
computers as you like, but they have no techical support.
For Windows 2000. These files contain all the sample code
from the book. You can browse these files directly from the
CD-ROM, or you can copy them to your hard drive and use
them as the basis for your own projects. To find the files on
the CD-ROM, open the D:\RESOURCES\CODE.EXE. To copy
the files to your hard drive, just run the installation program
D:\RESOURCES\CODE.EXE. The files will be placed on your
hard drive at C:\ProgramFiles\CSHARP. After installation,
you can access the files fromthe START menu. You will need
to have the .NET framework installed on the machine in
order to run the samples.
ACROBAT VERSION
Acrobat Reader
290
1873601-X AppB.F
10/18/01
12:04 PM
Page 291
ASPEdit 2000
XtraGrid
Internet Explorer
Freeware. Microsoft Internet Explorer is the most popular
World Wide Web browser for Windows. You need Internet
Explorer to access the Microsoft Web site when you need
help with C#. From Microsoft, www.adobe.com.
MineC#weeper
TROUBLESHOOTING
We tried our best to compile programs that work on most
computers with the minimum system requirements. Your
computer, however, may differ and some programs may not
work properly for some reason.
The two most likely problems are that you dont have
enough memory (RAM) for the programs you want to use,
or you have other programs running that are affecting
installation or running of a program. If you get error
messages like Not enough memory or Setup cannot
continue, try one or more of these methods and then try
using the software again:
TextPad
VMware Workstation
XPressSideBar
Freeware. A sample application that emulates the look and
feel of the side navigation bar popularized with Microsoft
Outlook. This application comes with full source code so
you can see how you can use C# to program applications.
You can download this application when you sign up for the
Developer Express beta program. From Developer Express,
www.devexpress.com.
291
1873601-X AppB.F
10/18/01
12:04 PM
Page 292
APPENDIX
First page
ZOOM IN
Previous page
Click
Next page
Last page
292
to magnify an
area of the page.
1873601-X AppB.F
10/18/01
12:04 PM
Page 293
FIND TEXT
Click
find.
appears.
293
1873601-X AppB.F
10/18/01
12:04 PM
Page 294
APPENDIX
294
1873601-X AppB.F
10/18/01
12:04 PM
Page 295
295
193601-X Index.F
10/18/01
12:04 PM
Page 296
INDEX
Symbols & Numbers
+, additive operator, 42
*/, asterisk-slash characters
ending a comment, 55
XML documentation, 59
@,at sign character, verbatim string
literal, 158
\, backslash character, escape
sequences, 159
>,caret mark, truncated button bar
indicator, 31
{ }, curly braces
enumerations, 156
interface accessors, 194
=!, equal sign/exclamation point, equality
operator, 42
==, equal signs character
equality operator, 42, 99
string comparisons, 164
!=, inequality operator, string
comparisons, 99
//, slash marks
comment indicator, 54
XML documentation, 58
/*, slash-asterisk characters
beginning a comment, 55
XML documentation, 59
[ ], square brackets, arrays, 136
A
abstract
keyword
base class specification, 71
properties, 192193
class
described, 66
XMLWriter, 246
properties
declarations, 192193
described, 192
restrictions, 193
accessibility levels, classes, 5253
accessors
described, 184
get, 110
interface, 194
set, 110
Acrobat Reader, e-version of book, 290
Active Server Pages (ASP), 10
Add Class Wizard, 5051, 6769
Add Interface Indexer Wizard, 154155
Add Method Wizard
adding
methods, 116119
static methods, 123
296
B
backups, before installing Visual
studio.NET, 37
base class
abstract keyword, 71
described, 68
base keyword, 76
blocks
catch, 274, 280
try/catch, 280
books
Contents window groupings, 1617
scrolling topics, 17
bool keyword, 9697
bool type, 88
Boolean type
conversion non-support, 97
described, 86, 9697
value assignments, 9697
boxing
described, 104
value type/reference type conversions,
104105
bug reports, logging, 6263
Build Number version, 266
building blocks, 64
193601-X Index.F
10/18/01
12:04 PM
Page 297
C#:
Your visual blueprint for
building .NET applications
built-in reference types, 42
Built-In Types Table, online help, 87
buttons, adding/removing toolbar, 30
byte, integer type, 88, 9293
C
C language, versus C#, 2
C# language
COM/Platform support, 3
comparisons
versus C language, 2
versus C++ language, 2
versus Java, 3
development history, 2
DLLs (dynamic link libraries), 3
Extensible Markup Language (XML), 3
integration, 2
JScript .NET support, 1213
security issues, 2
C# Language Tour link, accessing, 17
C++ language
copying comments to C# language, 55
versus C#, 2
case statements, examples, 287
cast expressions, 88
catch block
described, 274
implementation, 281
catch clauses, 278
CD-ROM
Acrobat Reader, 290
Acrobat version of book, 290
Antechinus C# Programming
Editor, 290
ASPEdit 2000, 291
authors source code, 290
e-version of book, 292293
installation/use of software, 290
Internet Explorer, 291
MineC#weeper, 291
program versions, 290
system requirements, 290
TextPad, 291
troubleshooting, 291
VMWare Workstation, 291
XPressSideBar, 291
XtraGrid, 291
char,
integer type, 9293
type, 88
characters
changing case, 172173
removing, 176177
replacing, 168169
types, 40
clients
assemblies
private, 256257
shared, 262263
versioned assembly configuration,
268269
Clipboard Ring group, Toolbox
components, 2223
code
comment addition, 5455
errors, 25
executing using try/catch blocks,
278279
summary comment addition, 51
type-safe, 102
code errors, 25
code-behind page, Web Forms, 220, 225
collections class
described, 150, 257
implementing, 150151
information retrieval, 150151
colors
comment indicator, 54
environment settings, 33
COM (Component Object Model),
development history, 252
COM/Platform, C# language support, 3
COM+, development history, 252
combine, program types
command-line, isql utility, 241
commands
ADO.NET, 231
csc, 203
comments
adding to code, 5455
asterisk-slash (*/) characters, 55
copying
from C++, 55
from Java, 55
described, 54
examples, 286
green color in code, 54
indexer interface, 114
multiple line support, 54
slash marks (//), 54
slash-asterisk (/*) characters, 55
summary, 51
CompareTo method, string
comparisons, 165
Comparison Between C++/C# help
page, 19
comparison methods, substring searches,
166167
compatibility, version scenarios, 267
Component Object Model (COM),
development history, 252
297
193601-X Index.F
10/18/01
12:04 PM
Page 298
INDEX
Concat method, concatenating strings,
160161
concatenating (joining) strings, 162163
Conditional attribute, 46, 48
connections, ADO.NET, 230
ConnectionString property, SQL database
insertion, 236237
Console.WriteLine statement
arrays, 144
collections class implementation, 150
constant expressions
arithmetic expressions, 88
described, 88
including in other constants, 89
literal keywords, 88
types, 88
constants
assigning to enumeration elements, 41
including in constant expressions, 89
constructors
described, 74
initializer, 76
program instance, 7677
Contents window, screen elements, 1617
controls
DataGrid, 232235
forms, 208209
Web Forms, 216
Web server, 222223
Create New Web dialog box, 219
csc command, 203
Ctrl key, moving between window
panes, 35
custom toolbar, creating, 2829
Customize dialog box, custom toolbar
creation, 28
Customize Toolbox window,
adding/removing components, 23
D
data
access code, try/catch blocks, 283
adapters, ADO.NET, 231
members, class component, 50
databases
SQL data insertion, 236237
SQL data update, 238239
DataGrid, Web Server Control, 232235
DCOM (Distributed COM), development
history, 252
decimal type, 86, 88
decimal numeric types, 92
decimal types, 94
298
declarations
abstract properties, 192193
arrays, 137
collections class, 150151
properties, 184
reference types, 98103
declarative reference types, 42
Default Values Table, online help, 87
delegate keyword, 86, 98
delegate objects, reference types, 102103
delegates
declarative reference type, 42
described, 130
entry conventions, 130131
delete statement, SQL data deletion,
240241
desktop, Visual Studio .NET startup
shortcut, 5
destructors
described, 74, 78
inserting, 7879
devenv.exe file, default file path, 5
dialog boxes See modal forms
distributed applications
assemblies, 253
private, 252, 254259
shared, 260269
configuration file paths, 259
deploying
with private assemblies, 258259
with shared assemblies, 264265
DLL Hell, 252
global assemblies, 252
namespaces, 253
side-by-side execution, 253
version binding policy, 268
versioned assembly configuration,
268269
versioning, 253
Web Services, 253, 270273
xcopy utility, 258259
Distributed COM (DCOM), development
history, 252
Distributed interNet Applications
(DNA), 252
DLL (Dynamic Ling Libraries), C# language
support, 3
DLL Hell, 252
DNA (Distributed interNet
Applications), 252
Document Property Pages window
(Shift+F4), 13
documentation
access methods, 6061
eXtensible Markup Language (XML),
5859
E
e-version of book, viewing on CD-ROM,
292293
electronic sticky notes, Task List, 2425
elements, searching for, 249
EndsWith method, substring search,
166167
enum keyword, enumerations, 156
enumeration type, value type, 86, 90916
enumeration types, 40
enumerations
adding to code, 156157
converting to integral type, 157
curly brackets { and }, 156
described, 156
error information, passing, 274
errors
handling, 274
importance of handling, 278
logging, 284
passing back to client 276277
trapping with catch block, 280281
writing to application log, 284285
escape sequences
backslash (\) character, 159
string literals, 158159
event handlers, 134135
Event Log, setting up/logging to, 284285
events
calling from classes, 133
code-behind page creation, 225
declaring, 132133
described, 102
server-side control response, 224225
exceptions
catching, 274
finally block, 282283
handling
catch block, 280281
implementation, 275
model, 275
.NET, 274
structured, 289
unified, 274
throwing, 274, 276277
Explicit Numeric Conversions Table, online
help, 87
193601-X Index.F
10/18/01
12:04 PM
Page 299
C#:
Your visual blueprint for
building .NET applications
Explorer-style interface, forms, 206
expressions
cast, 88
regular, 166167
eXtensible Markup Language (XML)
applying XSL, 250251
asterisk-slash (*/) characters, 58
C# language support, 3
development history
documentation
access, 6061
entry conventions, 5859
query with XPath, 248249
read from file, 244245
saving to file, 246247
slash marks (///), 58
slash-asterisk (/*) characters, 58
verbatim strings, 247
Web Services support, 270
F
false keyword, 88
Feedback link, Visual studio.NET, 63
fields, public, 254255
filename extensions
asmx (Web Services), 270
aspx (Web Forms), 216
aspx.cs (Web Forms), 217
aspx.vb (Visual Basic), 220
vsdisco (Web Services), 270
files
devenv.exe, 5
Gactuil.exe, 261
hello.exe, 5657
Ilasm.exe (MSIL Assembler), 261
Ildasm.exe, 261
opening existing projects, 3637
reading XML from, 244245
saving XML to, 246247
Sn.exe, 261
Filter drop-down list, filtering Web
information, 9
Filtered By drop-down list, Contents
window information display, 16
filters
Contents window information
display, 16
Index window information display, 18
search criteria, 2021
Web information, 9
finally
block
described, 278
using, 282283
statement, 283
G
GAC (Global Assembly Cache)
assembly registration, 260
client applications, 262263
described, 253
Gactuil.exe file, 261
shared assembly registration, 264
Gactuil.exe file, GAC content
manipulation, 261
General group, Toolbox components, 22
get accessor, interface properties, 110
get keywords, properties, 186191
GetCustomAttributes
class, 47
method, 47
GetType() method, value type display, 91
global assemblies, distributed
applications, 252
Global Assembly Cache (GAC)
assembly registration, 260
client applications, 262263
described, 253
Gactuil.exe file, 261
shared assembly registration, 264
graphical user interface (GUI)
described, 10
Web form support, 10
H
HailStorm Services, 273
hashmarks, toolbar indicator, 3031
hashtable, collections class information
retrieval, 151
heaps
described, 84
memory allocations, 8485
Hello, world! program, 5657
hello.exe file, 5657
Help Search in Progress dialog box, 20
Help system
access methods, 8
Arrays Tutorial, 137
Built-In Types Table, 87
C# Language Tour link, 17
Default Values Table, 87
Explicit Numeric Conversions Table, 87
filtering results, 9
Implicit Numeric Conversions Table, 87
Index window, 1819
Language Equivalent: Types page, 87
online help access methods, 6061
ScreenTips, 2829
search criteria, 2021
switching between help topics, 19
help topics
scrolling, 17
search criteria, 2021
switching between, 19
History icon, recently opened projects, 36
HTML button, displaying Web project code,
11, 13
HTML Controls, Web Forms, 216
HTTPRequest object, Web Forms, 229
Hypertext Markup Language (HTML), XML
development history, 58
HyperText Transport Protocol (HTTP), Web
Services support, 270
299
193601-X Index.F
10/18/01
12:04 PM
Page 300
INDEX
I
ICloneable interface, 160
IComparable interface
described, 160
sorting arrays, 146
IComparer interface, sorting arrays, 146
IConvertible interface, 160
IEnumerable interface
collections class implementation, 150
described, 160
IEnumerator interface, collections class
implementation, 150
if...else statements
C# language comparisons, 3
examples, 286
Ilasm.exe file (MSIL Assembler), 261
Ildasm.exe file, MSIL Assembler text file
creation, 261
immutable, 160
Implicit Numeric Conversions Table, online
help, 87
Index
Indexer Wizard, 112113
indexers
adding to code, 154155
described, 154
property comparisons, 186187
versus properties, 115
interface, 112115
Results window, accessing, 18
window, screen elements, 1819
inheritance
described, 7273
struct limitations, 81
inherited forms, 200201
initializers, constructors, 76
insert statement, SQL database insertion,
236237
installation/use of software, CD-ROM, 290
instances, 74
int, integer type, 88, 9293
integer types
converting, 93
numeric types, 92
signed, 9293
unsigned, 9293
integral type, 86
integration, C# language/Visual Studio
.NET, 2
IntelliSense, 25
interfaces
accessors, curly braces { and }, 194
declarative reference type, 42
ICloneable, 160
300
J
jagged arrays (array-of-arrays)
adding to code, 142143
described, 136
Java language
copying comments to C# language, 55
versus C# language, 3
JavaScript language
enabling Web pages, 13
versus JScript.NET, 12
joining (concatenating) strings, 162163
joins, strings, 180181
JScript .NET
described, 12
versus JavaScript, 12
K
keyboard combinations
Ctrl+Shift+C (Class View Window), 15
Ctrl+C (Copy), 23
Ctrl+Shift+V (Clipboard Ring), 23
Ctrl+V (Paste), 23
Ctrl+X (Cut), 23
Shift+F4 (Document Property Pages
WIndow), 13
keywords
abstract, 71, 192193
base, 76
bool, 9697
class, 86, 98
class-related, 69
delegate, 86, 98
enum, 156
false, 88
get, 186191
interface, 86, 98
internal, 53
new, 194195
null, 88
object, 86
return, 119
set, 186191
string, 86
this, 7576, 126
true, 88
unsafe, 106
L
Language Equivalent: Types page, online
help, 87
layouts
Explorer-style interface forms, 206
forms, 206209
multiple-document interface
forms, 206
single-document interface (SDI)
forms, 206
Length property, Main method, 39
licensing agreement, 294295
links
C# Language Tour, 17
Feedback, 63
Item Management in Projects, 19
Online Community, 8
Whats New, 8
list view, Toolbox window, 23
Location property, positioning forms,
210211
logical operators, 44
logins, password requirements, 6263
long, integer type, 88, 9293
Look in field, opening existing projects, 36
loops
FOR, 3
WHILE, 3
M
Main method
described, 3839
Length property, 39
return statement, 39
MainMenu, Toolbox component, 22
Major version, 266
MDE. See Microsoft Development
Environment
member-access format, static method
references, 125
193601-X Index.F
10/18/01
12:04 PM
Page 301
C#:
Your visual blueprint for
building .NET applications
memory
heaps, 8485
stacks, 8485
menu bar, Class View window access, 15
methods
Add Method Wizard, 116119
adding, 116129
arrays
Array.IndexOf, 148149
Array.LastIndexOf, 149
Array.Sort, 146147
CompareTo, 165
comparison, 166167
Concat, 160161
described, 116
EndsWith, 166167
event-handling, 134135
forms
Form.Show, 204205
Form.ShowDialog, 205
GetCustomAttributes, 47
GetType(), 91
Main, 3839
modifiers, 120121
naming concerns, 117
non-static, 116, 126129
overloading, 116
Read, 244
Select, 248
signatures, 116
StartsWith, 166167
static, 116, 122125
strings
String.Join, 180181
String.PadLeft, 182183
String.PadRight, 182183
String.Remove, 176177
String.Replace, 168169
String.Split, 178179
String.ToLower, 172173
String.ToUpper, 172173
String.Trim, 174175
String.TrimEnd, 174175
String.TrimStart, 174175
StringBuilder.Replace, 168
viewing information, 116117
Microsoft Developers Network (MSDN),
accessing from Visual studio.NET, 4
Microsoft Development Environment (MDE)
Built-In Types Table, 87
custom toolbars, 2829
Default Values Table, 87
deleting toolbars, 3031
devenv.exe file path, 5
empty environment startup, 5
N
namespaces
described, 52, 253
identifying, 67
System.Collections, 150
.NET Framework Common Language
Runtime, Web project requirement, 11
new keyword, including properties on
interfaces, 194195
O
objects
built-in reference type, 42
delegate, 102103
described, 42
destructors, 7879
form properties, 2627
HTTPRequest, 229
initial property settings, 263
keyword, 86
members of a class, 66
public fields, 254255
references, set to nothing example, 289
set reference to nothing, 289
String, 160
type, 90
unboxing, 43
Web Forms property editing, 226227
Obsolete attribute, 46, 48
Online Community link, VS Start Page, 8
online help
access methods, 6061
Built-In Types Table, 87
Default Values Table, 87
Explicit Numeric Conversions Table, 87
Implicit Numeric Conversions Table, 87
Language Equivalent: Types page, 87
online resources, Visual studio.NET, 89
Opacity property, transparent forms,
214215
Open Project button, opening existing
projects, 4, 36
301
193601-X Index.F
10/18/01
12:04 PM
Page 302
INDEX
Open Project window, opening existing
projects, 5, 3637
operators
adding to programs, 4445
additive (+), 42
arithmetical, 44
described, 44
equality (==), 42, 99
inequality (!=), 99
logical, 44
overloading, 45
relational, 44
P
parameter
passing by reference, examples, 288
passing by value, examples, 288
parent window
described, 34
Multiple Document Interface mode,
3435
resizing to maximum display, 35
screen elements, 3435
Tabs on Documents mode, 3435
passwords
conventions, 63
login, 6263
pointer type
described, 86, 106
nesting fixed statements, 107
private assemblies
application creation, 256257
client creation, 256157
configuration file paths, 259
creating, 254255
deploying applications, 258259
described, 254
distributed applications, 252, 254259
public fields, 254255
profiles, Visual Studio .NET, 4
programs
class library, 6
combining types, 4041
Hello, world!, 5657
running (F5), 41
types, combining, 4041
versions, CD-ROM, 290
Web control library, 6
Web service, 6
Windows control library, 6
Windows service, 6
writing conventions, 5657
Project location window, project folder
listing, 67
302
projects
opening existing, 45, 3637
saving before exiting Visual
studio.NET, 35
starting new, 57
template selections, 6
Web, 1011
properties
abstract declarations, 192193
accessibility issues, 185
accessor programming, 188191
accessors, 184
adding accessors, 190191
ConnectionString, 236237
declarations, 184
described, 184
displaying, 15
form editing, 212213
indexer comparisons, 186187
interface, 110111
interfaces, 194195
Length, 39
limitations, 187
Location, 210211
NodeType, 244
Opacity, 214
overriding accessors, 189
Property Wizard, 190191
read-only, 111
versus indexers, 115
viewing information, 184
Web Form object editing, 226227
window
C# language property information
display, 4
class properties display, 15
closing, 8
form properties, 2627
form property editing, 212213
startup methods, 27
Property Wizard, 190191
public fields, private assemblies, 254255
R
Read method, 244
rectangular (multidimensional) arrays
adding, 140141
described, 136
reference type, 86
reference types
built-in, 42
declarations, 98103
declarative, 42
delegate object, 102103
described, 4243
strings, 42
value type conversions, 104105
references, constant expressions, 88
reflection process, attribute information
retrieval, 46
regular expressions, substring search,
166167
relational operators, 44
reports, bug, 6263
return keyword, method support, 119
return statement
get accessor, 188
Main method, 39
Revision version, 266
S
sbyte type
described, 88
signed integer type, 93
ScreenTips, toolbar button help, 2829
Script Editor, Microsoft Script Debugger
component, 13
scrollbars, scrolling topics, 17
Search Results window, search result
display, 2021
searches
arrays, 148149
documentation, 6061
EndsWith method, 166
Help system, 2021
last five Index window display, 19
MSDN Online, 61
StartsWith method, 166
substrings, 166167
window, Help system search, 2021
security
C# language, 2
password storage, 63
Visual Studio .NET, 2
Web project considerations, 11
Select Component dialog box, 263, 269
Select method, 248
server controls
event response, 224225
Web Forms, 222223
services
ASP.NET support, 10
HailStorm, 273
System.Data, 228
System.Diagnostics, 228
System.IO, 228
System.Messaging, 228
System.XML, 228
set accessor, interface properties, 110
193601-X Index.F
10/18/01
12:04 PM
Page 303
C#:
Your visual blueprint for
building .NET applications
set keywords, properties, 186191
SGML (Standard Generalized Markup
Language), XML development history, 58
shared assemblies
client creation, 262263
creating, 260261
deploying, 264265
GAC registration, 264
Gactuil.exe file, 261
Ilasm.exe file (MSIL Assembler), 261
Ildasm.exe file, 261
MSIL Disassembler, 261
registering in Global Assembly Cache
(GAC), 260
shared name, 260
Sn.exe file, 261
strong name, 260
version
compatibility scenarios, 267
numbers, 266267
shared name, shared assemblies, 260
short type
described, 88
integer type, 9293
shortcuts, Visual Studio .NET startup, 5
side-by-side execution, 253
signatures, methods, 116
signed integer types, 929393
Simple Object Access Protocol (SOAP),
270, 272
simple types, 90
single-dimensional arrays
described, 136
entry conventions, 138139
omitting optional parts, 139
single-document interface (SDI), forms, 206
skeleton Main method, 38
Sn.exe file, strong name creation, 261
SOAP (Simple Object Access Protocol),
270, 272
Solution Explorer
closing, 8
window
adding a class, 50, 7071
C# language information display, 4
sorts
arrays, 146147
classes, 14
source code of author, CD-ROM, 290
SQL database
data
deletion, 240241
insertion, 236237
updating, 238239
stored procedure execution, 242243
stacks
described, 84
memory allocations, 8485
Standard Generalized Markup Language
(SGML), XML development history, 58
Standard toolbar, adding/removing
buttons, 30
StartsWith method, substring search,
166167
statements
Console.WriteLine, 144, 150
delete, 240241
finally, 283
for, 145
foreach, 144145, 150151
if-else, 3
insert, 236237
return, 39, 188
throw, 188
update, 238239
static member, class element, 74
static methods
adding, 122125
described, 116
member-access format references, 125
modifiers, 122123
simple names, 124125
this keyword, 126
stored procedures, executing in a SQL
database, 242243
strikethrough lines, completed tasks, 25
StringBuilder class
concatenating strings, 163
replacing string characters, 168169
StringBuilder.Replace method, replacing
characters, 168169
strings
changing case, 172173
class
described, 160
replacing string characters,
168169
comparing, 164165
concatenating, 162163
described, 42
equality (==) operator, 99
inequality (!=) operator, 99
joining, 180181
keyword, 86
literals
described, 158
escape sequences, 158159
verbatim versus regular, 158
methods
String.Join, joining strings, 180181
String.PadLeft , padding strings,
182183
String.PadRight, padding strings,
182183
String.Remove, removing
characters, 176177
String.Replace, replacing
characters, 168169
String.Split, splitting strings,
178179
String.ToLower, changing case,
172173
String.ToUpper, changing case,
172173
String.Trim, trimming white space,
174175
String.TrimEnd, trimming white
space, 174175
String.TrimStart, trimming white
space, 174175
object, data type conversions, 160
padding, 182183
removing characters, 176177
replacing characters, 168169
splitting, 178179
trimming white space, 174175
types, 88, 90, 98
value assignments, 160161
verbatim, 247
strong name
shared assemblies, 260
Sn.exe file, 261
struct type, value type, 86, 9091
structs
attributes, 153
constructor parameters, 82
described, 80, 152
limitations, 81
versus classes, 82
structured exception handling,
examples, 289
structures, 64
substrings
extracting, 170171
search methods, 166167
summary comments, adding to code, 51
system requirements, CD-ROM, 290
System.Array class, building arrays, 150
System.Attribute class, 4647
System.Boolean type, 96
System.Collections namespace, array
declarations, 150
System.Data service, Web Forms, 228
303
193601-X Index.F
10/18/01
12:04 PM
Page 304
INDEX
System.Diagnostics service, Web Forms, 228
System.Exception Framework class, 274
System.IO service, Web Forms, 228
System.Messaging service, Web Forms, 228
system.XML namespace, 244, 246
System.XML service, Web Forms, 228
T
Tab key, moving between window panes, 35
Tabs on Documents mode, 3435
target schemas, selecting from Document
Property Pages, 13
Task List
adding/removing tasks, 2425
strikethrough line with completed
task, 25
viewing tasks by type, 25
Task View window, comment tasks
display, 24
tasks
adding to Task List, 2425
strikethrough line when completed, 25
viewing by type, 25
templates
application types, 6
project startup, 6
TextPad, CD-ROM, 291
this keyword
described, 7576
static methods, 126
three-dimensional arrays, adding to code,
140141
throw statement
described, 276
get accessor, 188
toolbars
adding/removing buttons, 30
custom addition, 2829
deleting, 3031
docking, 31
floating, 30
hashmark indicator, 3031
resetting default, 29
ScreenTips button help, 2829
Toolbox
adding/removing components, 2223
Clipboard Ring grouping, 22
described, 22
form control addition, 208209
General grouping, 22
list view, 23
MainMenu component, 22
rearranging objects, 23
304
U
ulong type, 88
unboxing
described, 43, 104
value type/reference type conversions,
104105
Unicode character set, 93, 95
union attribute, creating, 83
unit type, 88
unsafe keyword, 106
unsigned integer type, 929393
update statement, SQL data update,
238239
V
value type
Boolean type, 9697
types, 86
converting to reference types,
104105
described, 9091
enumeration, 9091
struct, 9091
string assignments, 160161
variables
C# language comparisons, 3
described, 158
examples, 286
VB client, sample application, 265
verbatim strings
handcraft XML, 247
literal
at sign (@) character, 158
described, 158159
version binding policy, 268
versioning, 253
versions
Build Number, 266
compatibility scenarios, 267
Major, 266
Minor, 266
Revision, 266
shared assemblies, 266267
Visual Basic language
axpx.vb filename extension, 220
development history, 196197
Visual Studio .NET
ASP.NET integration, 10
backup before installing, 37
Contents window book grouping,
1617
empty environment startup, 5
environment settings, 3233
feedback capabilities, 63
Hello, world! program, 5657
Help system access, 8
integration, 2
login passwords, 6263
Microsoft Development Environment
(MDE), 4
online resources, 89
opening existing projects, 45, 3637
profiles, 4
project template selections, 6
193601-X Index.F
10/18/01
12:04 PM
Page 305
C#:
Your visual blueprint for
building .NET applications
resetting
default toolbars, 29
usage data, 29
reverting to older versions, 4
saving work before closing, 35
screen elements, 45
security, 2
starting new project, 57
startup methods, 4
System.Boolean type, 96
XML (eXtensible Markup Language)
support, 3
VMWare Workstation, CD-ROM, 291
void type
described, 86, 108109
return keyword non-support, 119
VS-Visual Studio Start Page window
maximizing, 41
MDE component, 4
Online Community link, 8
project template selections, 6
starting new project, 67
viewing property information, 184185
Web project startup, 1011
Whats New link, 8
W
Ways to Implement Component
Functionality page, 65
Web control library, supported program
type, 6
Web Forms
ASP.NET Framework, 216217
aspx filename extension, 216
aspx.cs filename extensions, 217
asynchronous messaging, 228
code-behind page, 220, 225
controls, 216
creating, 220221
described, 10
HTML Controls, 216
object property editing, 226227
server controls, 222223
server-side
code implementation, 221
components, 228229
control event response, 224225
Web Server Controls, 216
Web pages
ASP.NET creation, 218219
enabling JavaScript, 13
Web project
opening in VS Start Page, 1011
security issues, 11
Web server requirements, 11
Web Server Controls
DataGrid, 232235
Web Forms, 216
Web servers, Web project requirements, 11
Web Services
asmx filename extensions, 270
creating, 270271
described, 253, 270
eXtensible Markup Language (XML)
support, 270
HailStorm, 273
HyperText Transport Protocol
(HTTP), 270
Simple Object Access Protocol (SOAP),
270, 272
supported program type, 6
uses, 272273
vsdisco filename extension, 270
Web sites
Microsoft Developers Network
(MSDN), 4, 13
XML specifications, 246
Whats New link, VS Start Page, 8
WHILE loops
C# language comparisons, 3
examples, 288
white space
padding strings, 182183
trimming, 174175
windows
closing, 8
Ctrl key navigation, 35
hiding/displaying, 35
Multiple Document Interface mode,
3435
parent, 34
Tab key navigation, 35
Tabs on Documents mode, 3435
Windows control library, supported
program type, 6
Windows Form Designer
described, 198199
form layouts, 206209
positioning forms, 210211
Windows Media Player, MSDN Online
requirement, 61
Windows service, supported program
type, 6
Windows versions
memory allocation methods, 85
Microsoft.NET Framework SDK
support, 218
wizards
Add Class, 5051, 6769
Add Interface Indexer, 154155
Add Method, 116119
Indexer, 112113
Property, 190191
X
xcopy utility
distributed application deployment,
258259
private assembly sharing, 253
XML (eXtensible Markup Language)
applying XSL, 250251
asterisk-slash (*/) characters, 58
C# language support, 3
development history
documentation
access, 6061
entry conventions, 5859
query with XPath, 248249
read from file, 244245
saving to file, 246247
slash marks (///), 58
slash-asterisk (/*) characters, 58
verbatim strings, 247
Web Services support, 270
XML documents, caching, 248
XMLNodeReader class, 244
XMLReader class, 244245
XMLTextReader class, 244
XMLValidatingReader class, 244
XMLWriter abstract class, 246
XPath, query XML, 248249
XPath Document class, 248
XPathExpression class, 248
XPathNavigator class, 248
XPathNodeIterator class, 248
XPressSideBar, CD-ROM, 291
XSL, apply to XML, 250251
XSLT transformation, using, 250
XtraGrid, CD-ROM, 291
Z
zero index, 170
Zip drives, backup file uses, 37
305