this print for content only—size & color not accurate 7" x 9-1/4" / CASEBOUND / MALLOY2.125 INCH BULK -- 1,400 pages -- 40# Thor The eXPeRT’s VOIce® In .neT Andrew Troelsen Pro C# 2008 .
Trang 1this print for content only—size & color not accurate 7" x 9-1/4" / CASEBOUND / MALLOY
(2.125 INCH BULK 1,400 pages 40# Thor)
The eXPeRT’s VOIce® In neT
Andrew Troelsen
Pro
C# 2008
.NET 3.5 Platform
Exploring the NET universe using curly brackets
BOOks fOR PROfessIOnals By PROfessIOnals®
Pro C# 2008 and the NET 3.5 Platform, FourTh EdiTioN
Dear Reader, The first edition of this book was released at the 2001 Tech·Ed conference in Atlanta, Georgia (I honestly can’t believe it was that long ago!) Since that time, this text has been revised, tweaked, and enhanced to account for the changes found within each release of the NET platform (1.1, 2.0, 3.0, and now 3.5)
.NET 3.0 was more of an augmentative release, essentially providing three new APIs: Windows Presentation Foundation (WPF), Windows Communication Foundation (WCF), and Windows Workflow Foundation (WF) As you would expect, coverage of the “W’s” has been expanded upon a great deal from the previous Special Edition of this text
Unlike NET 3.0, NET 3.5 provides dozens of new C# language features and NET
APIs This edition of the book will walk you through all of this new material using the same readable approach (at least that is what I have been told!) as found
in the prior editions Rest assured, you’ll find detailed coverage of Language Integrated Query (LINQ), the C# 2008 language changes (automatic properties, extension methods, anonymous types, etc.), and the numerous bells and whistles
of Visual Studio 2008
If you’re checking out this book for the first time, understand that it targets experienced software professionals and/or students of computer science (so please don’t expect three chapters devoted to “for loops”) The mission of this text is to provide you with a rock-solid foundation in the C# 2008 programming language and the core aspects of the NET platform (OOP, assemblies, file IO, Windows Forms/WPF, ASP.NET, ADO.NET, WCF, WF, etc.) Once you digest the information presented in these 33 chapters, you’ll be in a perfect position to apply this knowledge to your specific programming assignments, and you’ll be well equipped to explore the NET universe on your own terms
Take care and enjoy, Andrew Troelsen Microsoft MVP, Visual Developer—Visual C#
THE APRESS ROADMAP
Pro ASP.NET 3.5
in C# 2008
Pro VB 2008 and the NET 3.5 Platform Accelerated C# 2008
Beginning C# 2008
Beginning C# 2008 Databases
Pro C# 2008 and the NET 3.5 Platform
Pro LINQ Pro WPF in C# 2008
Troelsen
MaGenTa Black
PanTOne 123 c
Author of
Pro VB 2008 and the
.NET 3.5 Platform
COM and NET
Interoperability
Expert ASP.NET 2.0
Advanced Application
Design
Developer’s Workshop
to COM and ATL 3.0
ISBN-13: 978-1-59059-884-9 ISBN-10: 1-59059-884-9
9 781590 598849
5 5 9 9 9
US $59.99
Shelve in
Programming/
Microsoft/.NET
User level:
Intermediate–Advanced
www.apress.com
SOURCE CODE ONLINE
Free Companion eBook
For a limited time only.
See last page for details.
FourTh EdiTioN
FourTh EdiTioN
Free Companion eBook Available
Pro
2008 and the Platfor NET 3.5
and the
For a limited time, get the free, fully searchable eBook—a $30 value!
See last page for details.
Offer ends June 30, 2008.
For a limited time, get the free, fully searchable eBook—a $30 value!
See last page for details.
Offer ends June 30, 2008.
Trang 3Andrew Troelsen
Pro C# 2008 and the NET 3.5 Platform
Fourth Edition
8849FM.qxd 10/19/07 9:45 AM Page i
Trang 4ISBN-10: 1-59059-884-9
Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1
Trademarked names may appear in this book Rather than use a trademark symbol with every occurrence
of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark
Lead Editor: Ewan Buckingham
Technical Reviewer: Gavin Smyth
Editorial Board: Steve Anglin, Ewan Buckingham, Tony Campbell, Gary Cornell, Jonathan Gennick, Jason Gilmore, Kevin Goff, Jonathan Hassell, Matthew Moodie, Joseph Ottinger, Jeffrey Pepper, Ben Renow-Clarke, Dominic Shakeshaft, Matt Wade, Tom Welsh
Production Director | Project Manager: Grace Wong
Senior Copy Editors: Ami Knox, Nicole Flores
Associate Production Director: Kari Brooks-Copony
Production Editor: Ellie Fountain
Compositor: Dina Quan
Proofreaders: April Eddy and Liz Welch
Indexer: Broccoli Information Management
Artist: Kinetic Publishing Services, LLC
Cover Designer: Kurt Krames
Manufacturing Director: Tom Debolski
Distributed to the book trade worldwide by Springer-Verlag New York, Inc., 233 Spring Street, 6th Floor, New York, NY 10013 Phone 1-800-SPRINGER, fax 201-348-4505, e-mail orders-ny@springer-sbm.com,
or visit http://www.springeronline.com
For information on translations, please contact Apress directly at 2855 Telegraph Avenue, Suite 600, Berkeley, CA 94705 Phone 510-549-5930, fax 510-549-5939, e-mail info@apress.com, or visit
http://www.apress.com
The information in this book is distributed on an “as is” basis, without warranty Although every precau-tion has been taken in the preparaprecau-tion of this work, neither the author(s) nor Apress shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly
or indirectly by the information contained in this work
The source code for this book is available to readers at http://www.apress.com in the Source Code/ Download section You will need to answer questions pertaining to this book in order to successfully download the code
Trang 5This edition of the text is dedicated to Mikko the wonder cat, life at 412, and my wonderful
wife, Amanda, who patiently waited for me to finish yet another book.
8849FM.qxd 10/19/07 9:45 AM Page iii
Trang 6Web Services Enhancements (WSE) 3.0, 873
Web Site template, 1190
web-centric primer, 1177
Web.config, ASP.NET, 1204, 1269–1270
Web.config file, 878, 913–914, 1163, 1178, 1188,
1191, 1203–1204, 1271–1272, 1274 WebControl class properties, ASP.NET, 1213
WebDev.WebServer.exe utility, 1166–1167, 1178,
1183 WebMethod attribute, 543, 870
WebService directive, 871
WebServiceFaultActivity, WF, 921
WebServiceInputActivity, WF, 921
WebServiceOutputActivity, WF, 921
website administration utility, ASP.NET, 1205–1206
website directory structure, ASP.NET, 1190
Web.sitemap file, 1219
where keyword, generics, 335
Where( ) method, 461
where operator, 463, 466
Where<T>( ) method, 461
While activity, 928–930
while loop, 101, 795
WhileActivity, WF, 921
widening, 95
widgets, 1169, 1248
Width member, 1061
Width property, 1085, 1137, 1213
Width value, 1087
Win 32 binaries (*.dll or *.exe), 11
Win32 file header in assemblies, 482
Window class
overview, 1006–1007 System.Windows.Controls.ContentControl base class, 1007–1008
System.Windows.Controls.Control base class, 1008–1009
System.Windows.DependencyObject base class, 1010
System.Windows.Media.Visual base class, 1010 System.Windows.Threading.DispatcherObject base class, 1011
System.Windows.UIElement base class, 1010 Window object
closing of, 1018–1019 lifetime of, 1017–1018 Window type, 1083, 1094, 1103, 1113, 1118
<Window> element, 1022, 1032, 1084, 1113, 1154
Window1 type, 1108
Window-derived type, 1121
Windows Forms, 556–557, 999 Windows Presentation Foundation (WPF), 955,
1318 See also Application type; Window
object assemblies overview, 1005 role of Application class, 1006 role of Window class, 1006–1011 building WPF applications using Visual Studio
2008, 1044–1048 building XAML-free WPF applications creating simple user interface, 1013–1015, 1021
extending Window class type, 1013 overview, 1011–1013
controlling content layout using panels, 1108 Extensible Application Markup Language (XAML)
attached properties, 1038–1039 Browser Applications (XBAPs), 1004 defining application object in, 1023, 1033 defining MainWindow in, 1022–1023 elements and attributes, 1035 experimenting with using XamlPad, 1032 markup extensions, 1039–1041
overview, 1021–1022 processing at runtime, 1048–1052 processing XAML files via msbuild.exe, 1023–1024
property-element syntax, 1036–1037 type converters, 1039
motivation behind overview, 999–1000 providing optimized rendering model, 1001 providing separation of concerns via XAML, 1001
separation of concerns using code-behind files, 1029–1030
transforming markup into NET assembly mapping XAML to C# code, 1025–1026 overview, 1025
role of Binary Application Markup Language (BAML), 1026–1028
XAML-to-assembly process summary, 1028–1029, 1052
Windows property, Application type, 1006 Windows Vista operating system, 1001 Windows Workflow Foundation (WF) assemblies and core namespaces, 924 brief word regarding custom activities, 951–952
Trang 7building blocks of getting into flow of workflow, 925–926 integrated services of WF, 919 overview, 918–919
role of sequential workflows and state machine workflows, 921–923
WF activities, 920–921 building reusable code library, 948–951 building simple workflow-enabled application adding Code activity, 927–928
adding custom start-up parameters, 931–935 adding While activity, 928–930
initial workflow code, 926–927 overview, 926
WF engine hosting code, 930–931 invoking web services within workflows, 934–935
motivation behind, 917–918 overview, 917
Windows Workflow toolbox, 920
Windows XP Home Edition and ASP.NET,
1166–1167 WindowsBase.dll assembly, WPF, 1005
Windows.Forms coding, 977
WindowsFormsDataTableViewer application, 799
WindowState property, 972
WindowTop property, 76
WindowWidth property, 76
WinFormsClientApp.cs file, 1328
Wizard definition, 1229
Wizard web control, 1228
worker thread, 562
WorkflowCompleted event, WorkflowRuntime, 931
workflow-enabled application, 918
WorkflowInstance core type, 930
WorkflowRuntime core type, 930
WorkflowTerminated event, WorkflowRuntime, 931
WrapPanel control, 1056, 1085, 1088
<WrapPanel> element, 1114
Write( ) method, 676, 678, 682, 1189, 1199
WriteAllBytes( ) method, 674
WriteAllLines( ) method, 674
WriteAllText( ) method, 674
WriteFile( ) method, 70, 153, 678, 1199
write-only class properties, 171
WriteOnly keyword, 165, 171
write-only property, 171
WriteTextToIsoStorage( ) method, 707
WriteXml( ) method, 796
WriteXmlSchema( ) method, 796
writing to a text file, 679
wsdl utility, 1322
wsdl.exe command-line tool, 872
WSDualHttpBinding class, 882
WSDualHttpBinding option, 881
WSFederationHttpBinding class, 882
WSFederationHttpBinding option, 881 WSHttpBinding class, 905
WSHttpBinding option, 881 WSHttpBinding protocol, 882, 901
X
X or x string format, NET, 78
X property, 976
*.xaml file, 1024, 1028, 1055, 1129 XamlPad, 1031–1032
XAttribute member, 859 XAttributes object, 859 x/COL/Type markup extension, 1151 XComment member, 859
Xcopy deployment, 499 XDeclaration member, 859 XDocument member, 859 XDocument type, 860 XElement member, 858 XElement parameter, 864 XElement type, 860 XElement.Descendants( ) method, 863 XElement.Load( ) method, 863 XElements object, 859 XML
and ADO.NET, 731 /doc compiler flag, 179 documentation elements, 177 documenting VB 2005 source code via, 176–180 source code documentation, 176–177
*.xml file, 179, 1114 XmlDataProvider type, 1114 XmlElement type, 1115 xmlns attribute, 1168 XmlReader/XmlWriter models, 858 XmlSerializer, 716, 720–722 XName/XNamespace member, 859 XPath bindings, 1114
xPos member variable, 437 xsd utility, 1322
xsp2 utility, 1322
Y
y operators, 448
Y property, 976 yetAnotherPoint variable, 437 yield keyword, 292–293 yPos member variable, 437
■I N D E X
1370
8849INDEX.qxd 10/18/07 5:51 PM Page 1370