Tải bản đầy đủ (.pdf) (1,695 trang)

2006 wiley beginning visual c sharp 2005

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (12.91 MB, 1,695 trang )

BeginningVisualC#2005
byKarliWatsonetal.
WroxPress2006(1102pages)
ISBN:0764578472

Withhelpfulhints,tips,exercises,andexamplecode,
thisbookcoverseverythingyouneedtoknowabout
VisualC#2005andthe.NETFrameworktocreate
secureapplicationsformobiledevices,Web
applications,Windowsapplications,andWebservices.

TableofContents
BeginningVisualC#2005
Introduction
PartI-TheC#Language
Chapter1 - IntroducingC#
Chapter2 - WritingaC#Program
Chapter3 - VariablesandExpressions
Chapter4 - FlowControl
Chapter5 - MoreaboutVariables
Chapter6 - Functions
Chapter7 - DebuggingandErrorHandling
Chapter8 - IntroductiontoObject-Oriented
Programming
Chapter9 - DefiningClasses
Chapter10 - DefiningClassMembers
Chapter11 - Collections,Comparisons,and
Conversions
Chapter12 - Generics
Chapter13 - AdditionalOOPTechniques



PartII-WindowsProgramming
Chapter14 - BasicWindowsProgramming
Chapter15 - AdvancedWindowsFormsFeatures
Chapter16 - UsingCommonDialogs
Chapter17 - DeployingWindowsApplications
PartIII-WebProgramming
Chapter18 - BasicWebProgramming
Chapter19 - AdvancedWebProgramming
Chapter20 - WebServices
Chapter21 - DeployingWebApplications
PartIV-DataAccess
Chapter22 - FileSystemData
Chapter23 - XML
Chapter24 - DatabasesandADO.NET
Chapter25 - DataBinding
PartV-AdditionalTechniques
Chapter26 - .NETAssemblies
Chapter27 - Attributes
Chapter28 - XMLDocumentation
Chapter29 - Networking
Chapter30 - IntroductiontoGDI+
Index
ListofFigures
ListofTryItOuts


BackCover
Creatingnext-generationsoftwareandapplicationsis
noweasierthaneverwiththereleaseofVisualC#

2005.Thisaccessiblebookguidesyouthroughall
aspectsofC#programmingandthecapabilitiesof
VisualStudio2005sothatyoucanbegindeveloping
customizedapplications.
You'llfirstlearnallaspectsoftheC#language,from
thefundamentalstoobject-orientedtechniques.You'll
thenquicklyprogressthroughWindowsandWeb
programmingtomakinguseofdatasources,and
finallytosomeadvancedtechniquessuchasXML
documentationandgraphicsprogrammingwithGDI+.
Throughoutthebook,you'llalsofindhelpfulhints,tips,
exercises,andfull-fledgedexamplecodethatwill
enhanceyourprogrammingskills.
Thisbookcoverseverythingyouneedtoknowabout
VisualC#2005andthe.NETFrameworktocreate
powerful,secureapplicationsformobiledevices,Web
applications,Windowsapplications,andWebservices.
Whatyouwilllearnfromthisbook
WaystoaddfunctionalitytoyourVisualC#
applications
HowtopublishapplicationstotheWebwiththe
clickofabutton
TechniquesforassemblingadvancedWindows
applicationswithaminimumofeffortandtime


TipsforusingWebservicestoaddcomplexdata
andfunctionalitytoWebapplications
HowtoimproveyourC#applicationsusing
object-orientedprogramming

StepsforusingADO.NETtointeractwith
databasesanddealwithXML
Whothisbookisfor
Thisbookisforanyonewhowantstolearnhowto
programinC#usingthe.NETFramework.Itisalsofor
programmerswhoknow.NET1.0andwanttofindout
aboutthelatestfeaturesof.NET2.0andVisualStudio
2005.


BeginningVisualC#2005
KarliWatson
ChristianNagel
JacobHammerPedersen
JonD.Reid
MorganSkinner
EricWhite
Publishedby
WileyPublishing,Inc.
10475CrosspointBoulevard
Indianapolis,IN46256
www.wiley.com
Copyright2006byWileyPublishing,Inc.,Indianapolis,Indiana
PublishedsimultaneouslyinCanada
ISBN-13:978-0-7645-7847-2
ISBN-10:0-7645-7847-2
ManufacturedintheUnitedStatesofAmerica
10987654321
1O/RR/RQ/QV/IN
LibraryofCongressCataloging-in-PublicationData:

BeginningVisualC#2005/KarliWatson...[etal.].
p.cm.
Updateded.of:BeginningVisualC#.2003.
Includesindex.
ISBN-13:978-0-7645-7847-2(paper/website)
ISBN-10:0-7645-7847-2(paper/website)
1.C#(Computerprogramlanguage)2.Microsoft.NETFramework.I.
Watson,Karli.II.BeginningVisualC#.QA76.73.C154B4832005
005.13'3--dc22


2005010692
Nopartofthispublicationmaybereproduced,storedinaretrieval
systemortransmittedinanyformorbyanymeans,electronic,
mechanical,photocopying,recording,scanningorotherwise,except
aspermittedunderSections107or108ofthe1976UnitedStates
CopyrightAct,withouteitherthepriorwrittenpermissionofthe
Publisher,orauthorizationthroughpaymentoftheappropriatepercopyfeetotheCopyrightClearanceCenter,222RosewoodDrive,
Danvers,MA01923,(978)750-8400,fax(978)646-8600.Requeststo
thePublisherforpermissionshouldbeaddressedtotheLegal
Department,WileyPublishing,Inc.,10475CrosspointBlvd.,
Indianapolis,IN46256,(317)572-3447,fax(317)572-4355,oronline
at />LIMITOFLIABILITY/DISCLAIMEROFWARRANTY:THE
PUBLISHERANDTHEAUTHORMAKENOREPRESENTATIONS
ORWARRANTIESWITHRESPECTTOTHEACCURACYOR
COMPLETENESSOFTHECONTENTSOFTHISWORKAND
SPECIFICALLYDISCLAIMALLWARRANTIES,INCLUDING
WITHOUTLIMITATIONWARRANTIESOFFITNESSFORA
PARTICULARPURPOSE.NOWARRANTYMAYBECREATED
OREXTENDEDBYSALESORPROMOTIONALMATERIALS.

THEADVICEANDSTRATEGIESCONTAINEDHEREINMAYNOT
BESUITABLEFOREVERYSITUATION.THISWORKISSOLD
WITHTHEUNDERSTANDINGTHATTHEPUBLISHERISNOT
ENGAGEDINRENDERINGLEGAL,ACCOUNTING,OROTHER
PROFESSIONALSERVICES.IFPROFESSIONALASSISTANCE
ISREQUIRED,THESERVICESOFACOMPETENT
PROFESSIONALPERSONSHOULDBESOUGHT.NEITHERTHE
PUBLISHERNORTHEAUTHORSHALLBELIABLEFOR
DAMAGESARISINGHEREFROM.THEFACTTHATAN
ORGANIZATIONORWEBSITEISREFERREDTOINTHISWORK
ASACITATIONAND/ORAPOTENTIALSOURCEOFFURTHER
INFORMATIONDOESNOTMEANTHATTHEAUTHORORTHE
PUBLISHERENDORSESTHEINFORMATIONTHE
ORGANIZATIONORWEBSITEMAYPROVIDEOR


RECOMMENDATIONSITMAYMAKE.FURTHER,READERS
SHOULDBEAWARETHATINTERNETWEBSITESLISTEDIN
THISWORKMAYHAVECHANGEDORDISAPPEARED
BETWEENWHENTHISWORKWASWRITTENANDWHENITIS
READ.
Forgeneralinformationonourotherproductsandservicesplease
contactourCustomerCareDepartmentwithintheUnitedStatesat
(800)762-2974,outsidetheUnitedStatesat(317)572-3993orfax
(317)572-4002.
Trademarks:Wiley,theWileylogo,Wrox,theWroxlogo,
ProgrammertoProgrammer,andrelatedtradedressaretrademarks
orregisteredtrademarksofJohnWiley&Sons,Inc.and/orits
affiliates,intheUnitedStatesandothercountries,andmaynotbe
usedwithoutwrittenpermission.VisualC#isaregisteredtrademark

ofMicrosoftCorporationintheUnitedStatesand/orothercountries.
Allothertrademarksarethepropertyoftheirrespectiveowners.Wiley
Publishing,Inc.,isnotassociatedwithanyproductorvendor
mentionedinthisbook.
Wileyalsopublishesitsbooksinavarietyofelectronicformats.Some
contentthatappearsinprintmaynotbeavailableinelectronicbooks.
Credits
AcquisitionsEditor
KatieMohr
DevelopmentEditor
TomDinse
TechnicalEditor
ToddMeister
ProductionEditor
AngelaSmith
CopyEditor


FoxxeEditorialServices
EditorialManager
MaryBethWakefield
VicePresident&ExecutiveGroupPublisher
RichardSwadley
VicePresidentandPublisher
JosephB.Wikert
ProjectCoordinators
RyanSteffen
ErinSmith
GraphicsandProductionSpecialists
AndreaDahl

DennyHager
JenniferHeleine
StephanieJumper
BarbaraMoore
ShelleyNorris
LynseyOsborn
HeatherRyan
AliciaSouth
RonTerry
JulieTrippetti
QualityControlTechnicians
LauraAlbert
LeeannHarney
CarlWilliamPierce
ProofreadingandIndexing
TECHBOOKSProductionServices
fordonna
—KarliWatson


I'dliketodedicatemyportionofthisbooktomywife,Beth,andour
childrenNathaniel,Timothy,andWalter.Thanksforyoursupportand
encouragement.Alsoabigthankyoutomyco-authorsandtheteam
atWrox/Wiley.
—JonReid
AbouttheAuthors
KarliWatsonisthetechnicaldirectorof3form(www.3form.net),as
wellasafreelanceITspecialist,author,developer,andconsultant.
Forthemostpart,heimmerseshimselfin.NET(inparticularC#)and
haswrittennumerousbooksinthefieldforseveralpublishers.He

specializesincommunicatingcomplexideasinawaythatis
accessibletoanyonewithapassiontolearn,andspendsmuchofhis
timeplayingwithnewtechnologytofindnewthingstoteachpeople
about.
Duringthose(seeminglyfew)timeswhereheisn'tdoingtheabove,
Karliwillprobablybewishinghewashurtlingdownamountainona
snowboard.Orpossiblytryingtogethisnovelpublished.Eitherway,
you'llknowhimbyhisbrightlycoloredclothes.
ChristianNagelisasoftwarearchitect,trainer,andconsultant,and
anassociateofThinktecture,offeringtrainingandcoachingbasedon
Microsoft.NETtechnologies.Hisachievementsinthedeveloper
communityhaveearnedhimapositionasMicrosoftRegionalDirector
andMVPforVisualC#.Heenjoysanexcellentreputationasan
authorofseveral.NETbooks,suchasProfessionalC#,Pro.NET
NetworkProgrammingandC#WebServices,andhespeaksregularly
atinternationalindustryconferences.
Christianlooksbackonmorethan15yearsofexperienceasa
developerandsoftwarearchitect.Hestartedhiscomputingcareeron
PDP11andVAX/VMS,coveringavarietyoflanguagesandplatforms.
Since2000hehasbeenworkingwith.NETandC#,developingand
architectingdistributedsolutions.




JacobHammerPedersenisasystemsdeveloperatFujitsuService,
Denmark.He'sbeenprogrammingthePCsincetheearly90susing
languagessuchasPascal,VisualBasic,C/C++,andinlateryears
C#.JacobisanMCSDwhoworksalmostexclusivelyontheMicrosoft
platformwherehisexpertiseincludes.NET,COM,COM+/Enterprise

Services,SQLServer,andMSOfficedevelopment.ADanishcitizen,
heworksandlivesinAarhus,Denmark.
JonD.ReidisthePresidentandChiefTechnologyOfficerforSavitar
Corporation,anindependentsoftwarevendorandconsulting
companythatdevelopsdatabasetoolsfortheMicrosoft.NET
environment.Hehasco-authoredmany.NETbooks,includingPro
VisualStudio.NET,FastTracktoC#Programming,ADO.NET
Programmer'sReference,andProfessionalSQLServer2000XML.
Jonwouldliketothankhisfamily,co-authors,andtheteamatWrox
fortheirsupportandencouragement.
MorganSkinnerbeganhiscomputingcareeratatenderageona
SinclairZX80atschool,wherehewasunderwhelmedbysomecode
ateacherhadwrittenandsobeganprogramminginassembly
language.AftergettinghookedonZ80(whichhebelievesisfarbetter
thanthosepaltry3registersonthe6502),hegraduatedthroughthe
school'sZX81stohisownZXSpectrum.
Sincethenhe'susedallsortsoflanguagesandplatforms,including
VAXMacroAssembler,Pascal,Modula2,Smalltalk,X86assembly
language,PowerBuilder,C/C++,VB,andcurrentlyC#.He'sbeen
programmingin.NETsincethePDCreleasein2000,andlikeditso
much,hejoinedMicrosoftin2001.HenowworksinPremierSupport
forDevelopersandspendsmostofhistimeassistingcustomerswith
C#.
YoucanreachMorganat.
EricWhiteisanindependentsoftwareconsultantwithover20years
experienceinbuildingmanagementinformationsystemsand


accountingsystems.Whenheisn'thunchedoverascreen
programminginC#,hewillmostlikelybefoundwithaniceaxein

hand,climbingsomemountain.


Introduction
C#isarelativelynewlanguagethatwasunveiledtotheworldwhen
Microsoftreleasedthefirstversionofits.NETFramework.Sincethen
itspopularityhasrocketed,andithasarguablybecomethelanguage
ofchoiceforbothWindowsandWebdeveloperswhouse.NET.Part
oftheappealofC#comesfromitsclearsyntax,whichderivesfrom
C/C++,butsimplifiessomethingsthathavepreviouslydiscouraged
someprogrammers.Despitethissimplification,C#hasretainedthe
powerofC++,andthereisnownoreasonnottomoveintoC#.The
languageisnotdifficult,andisanexcellentonetolearnelementary
programmingtechniqueswith.Thiseaseoflearning,combinedwith
thecapabilitiesofthe.NETFramework,makeC#anexcellentwayto
startyourprogrammingcareer.
ThelatestreleaseofC#,partof.NET2.0,buildsontheexisting
successesandaddsevenmoreattractivefeatures.Someofthese,
again,havetheirrootsinC++—atleastsuperficially—butsomeare
entirelynew.ThelatestreleaseofVisualStudioalsobringsmany
tweaksandimprovementstomakeyourlifeeasieranddramatically
increaseyourproductivity.
ThisbookisintendedtoteachyouaboutallaspectsofC#
programming,fromthelanguageitself,throughWindowsandWeb
programming,tomakinguseofdatasources,andfinallytosome
advancedtechniquessuchasgraphicsprogramming.You'llalsolearn
aboutthecapabilitiesofVisualStudio2005andallthewaysthatit
canaidyourapplicationdevelopment.Thebookiswritteninafriendly,
mentor-stylefashion,whereeachchapterbuildsonpreviousonesand
everyeffortismadetoeaseyouintoadvancedtechniquespainlessly.

Atnopointwilltechnicaltermsappearfromnowheretodiscourage
youfromcontinuing;everyconceptisintroducedanddiscussedas
required.Technicaljargoniskepttoaminimum,butwhereitis
necessary,ittoowillbeproperlydefinedandlaidoutincontext.
Theauthorsofthisbookareallexpertsintheirfield,andareall
enthusiasticintheirpassionforboththeC#languageandthe.NET
Framework.Nowherewillyoufindagroupofpeoplebetterqualifiedto


takeyouundertheircollectivewingandnurtureyourunderstandingof
C#fromfirstprinciplestoadvancedtechniques.Alongwiththe
fundamentalknowledgeitprovides,thisbookispackedfullofhelpful
hints,tips,exercises,andfully-fledgedexamplecode(availablefor
downloadatp2p.wrox.com)thatyouwillfindyourselfusingtime
andagainasyourcareerprogresses.
Wepassthisknowledgeonwithoutbegrudgingit,andhopethatyou
willbeabletouseittobecomethebestprogrammeryoucanbe.
Goodluck,andallthebest!


WhoThisBookIsFor
ThisbookisforeveryonewhowantstolearnhowtoprograminC#
usingthe.NETFramework.Theearlychapterscoverthelanguage
itself,assumingnopriorprogrammingexperience.Ifyouhave
programmedinotherlanguagesbefore,thenmuchofthematerialin
thesechapterswillbefamiliar.ManyaspectsofC#syntaxareshared
withotherlanguages,andmanystructuresarecommontopractically
allprogramminglanguages(suchasloopingandbranching
structures).However,evenifyouareanexperiencedprogrammeryou
willbenefitfromlookingthroughthesechapterstolearnthespecifics

ofhowthesetechniquesapplytoC#.
Ifyouarenewtoprogramming,youshouldstartfromthebeginning.If
youarenewto.NETbutknowhowtoprogram,youshouldread
Chapter1andthenskimthroughthenextfewchaptersbeforegetting
ontotheapplicationoftheC#language.Ifyouknowhowtoprogram
buthaven'tencounteredanobjectorientedprogramminglanguage
before,youshouldreadthechaptersfromChapter8onward.
Alternatively,ifyoualreadyknowtheC#languageyoumaywishto
concentrateonthechaptersdealingwith.NET2.0changes,
specificallythechaptersonCollectionsandGenerics(Chapters11
and12),orskipthefirstsectionofthebookcompletelyandstartwith
Chapter14.
Thechaptersinthisbookarewrittenwithadualpurposeinmind:
TheycanbereadsequentiallytoprovideacompletetutorialintheC#
language,andtheycanbedippedintoasrequiredasareference
material.
Inadditiontothecorematerial,eachchapteralsoincludesaselection
ofexercisesthatyoucanworkthroughtoensurethatyouhave
understoodthematerialtaught.Theexercisesrangefromsimple
multiplechoiceortrue/falsequestionstomoreinvolvedquestionsthat
requireyoutomodifyorbuildapplications.Theanswerstoallthe


exercisesareprovidedonlineatp2p.wrox.com.


HowThisBookIsStructured
Thisbookisdividedintosixsections,asfollows:
Introduction:whichyou'rereadingatthemoment.
TheC#Language:whichcoversallaspectsoftheC#

language,fromthefundamentalstoobject-oriented
techniques.
WindowsProgramming:thissectionlooksathowtowrite
WindowsapplicationsinC#,andhowtodeploythem.
WebProgramming:thissectiondescribesWebapplication
development,Webservices,andWebapplicationdeployment.
DataAccess:whichlooksatusingdatainyourapplications,
includingdatastoredinfilesonyourharddisk,datastoredin
XMLformat,anddataindatabases.
AdditionalTechniques:thissectionexaminessomeextra
waysofusingC#andthe.NETFramework,including
assemblies,attributes,XMLdocumentation,networking,and
graphicsprogrammingwithGDI+.
Thefollowingsectionsdescribethechaptersinthefivemajorsections
ofthisbook.

TheC#Language(Chapters1–13)
Chapter1introducesyoutoC#andhowitfitsintothe.NET
landscape.You'lllearnthefundamentalsofprogramminginthis
environment,andhowVSfitsin.
Chapter2startsyouoffwithwritingC#applicationsinVS.You'lllook
atthesyntaxofC#andputthelanguagetousewithsample
commandlineandWindowsapplications.Theseexampleswillshow
youjusthowquickandeasyitcanbetogetupandrunning,and
alongthewayyou'llbeintroducedtotheVSdevelopment


environmentandthebasicwindowsandtoolsthatyou'llbeusing
throughoutthebook.
Nextyou'lllearnmoreaboutthebasicsoftheC#language.You'll

learnwhatvariablesareandhowtomanipulatetheminChapter3.
You'llenhancethestructureofyourapplicationswithflowcontrol
(loopingandbranching)inChapter4,andseesomemoreadvanced
variabletypessuchasarraysinChapter5.InChapter6you'llstartto
encapsulateyourcodeintheformoffunctions,whichmakeitmuch
easiertoperformrepetitiveoperationsandmakeyourcodemuch
morereadable.
BythestartofChapter7you'llhaveahandleonthefundamentalsof
theC#language,andwillfocusondebuggingyourapplications.This
involveslookingatoutputtingtraceinformationasyourapplications
areexecuted,andathowVScanbeusedtotraperrorsandleadyou
tosolutionsforthemwithitspowerfuldebuggingenvironment.
FromChapter8onwardyou'lllearnaboutObject-Oriented
Programming(OOP),startingwithalookatwhatthistermmeans,
andananswertotheeternalquestion"Whatisanobject?"OOPcan
seemquitedifficultatfirst.ThewholeofChapter8isdevotedto
demystifyingitandexplainingwhatmakesitsogreat,andyouwon't
actuallybedealingwithmuchC#codeuntiltheveryendofthe
chapter.
AllthischangesinChapter9,whenyouputtheoryintopracticeand
startusingOOPinyourC#applications.Thisiswherethetruepower
ofC#lies.You'llstartbylookingathowtodefineclassesand
interfaces,thenmoveontoclassmembers(includingfields,
properties,andmethods)inChapter10.Attheendofthatchapter
you'llstarttoassembleacardgameapplication,whichwillbe
developedoverseveralchapters,andwillhelptoillustrateOOP.
Onceyou'veleanedhowOOPworksinC#,you'llmoveoninChapter
11tolookatcommonOOPscenarios,includingdealingwith
collectionsofobjects,andcomparingandconvertingobjects.Chapter
12thenmovesontolookatanewandveryusefulfeatureofC#in



.NET2.0:generics,whichallowsyoutocreateveryflexibleclasses.
FinallyChapter13roundsoffthediscussionoftheC#languageand
OOPwithsomeadditionaltechniques,andnotableevents,which
becomeveryimportantin,forexample,Windowsprogramming.

WindowsProgramming(Chapters14–17)
Chapter14startsbyintroducingyoutowhatismeantbyWindows
programming,andlooksathowthisisachievedinVS.Again,you'll
startwiththebasicsandbuildupyourknowledgeoverthischapter
andinChapter15,seeinghowyoucanusethewealthofcontrols
suppliedbythe.NETFrameworkinyourapplications.You'llquickly
understandhow.NETenablesyoutobuildWindowsapplicationsina
graphicalway,andassembleadvancedapplicationswiththeminimum
ofeffortandtime.
Chapter16looksatsomecommonlyusedfeaturesthatcanadd
specializedfeatureswithease,suchasfilemanagement,printing,and
soon.Chapter17thendiscussesdeployingyourapplications,
includingmakinginstallationprogramstoenableyouruserstogetup
andrunningwithyourapplicationsindouble-quicktime.

WebProgramming(Chapters18–21)
ThissectionisstructuredinasimilarwaytotheWindows
programmingsection.ItstartswithChapter18describingthecontrols
thatmakeupthesimplestofWebapplications,andhowyoucanfit
themtogetherandmakethemperformtasksusingASP.NET.Chapter
19buildsonthisandintroducesmoreadvancedtechniques,versatile
controls,andstatemanagementinthecontextoftheWeb,aswellas
conformingtoWebstandards.

Chapter20isanexcursionintothewonderfulworldofWebservices,
whicharesettorevolutionizethewaypeopleusetheInternet.Web
servicesenableyoutoexposecomplexdataandfunctionalitytoWeb
andwindowsapplicationsinaplatform-independentway.Thischapter
discusseshowtouseandcreateWebservices,andtheadditional
toolsthat.NETprovides,includingsecurity.


Finally,Chapter21examinesthedeploymentofWebapplications
andservices,inparticularthenewfeaturesofVSthatenableyouto
publishapplicationstotheWebwiththeclickofabutton.

DataAccess(Chapters22–25)
Chapter22looksathowyourapplicationscansaveandretrievedata
todisk,bothassimpletextfilesandasmorecomplexrepresentations
ofdata.You'llalsoseehowtocompressdata,howtoworkwith
legacydatasuchascommaseparatedvalue(CSV)files,andhowto
monitorandactonfilesystemchanges.
InChapter23you'lllearnaboutwhatisfastbecomingthede-facto
standardfordataexchange,namelyXML.You'llhavetouchedon
XMLatseveraltimesinprecedingchapters,butinthischapteryou'll
layoutthegroundrulesandseewhatalltheexcitementisabout.This
willbeputintopracticestraightawayinChapter24,whereyou'llsee
howtouseADO.NETtointeractwithdatabases.ADO.NETincludes
techniquestodealwithXML,andmuchmore.
Chapter25willthenshowyousomeexcellentwaystomakeuseof
ADO.NETinyourapplicationsviadatabinding,whichisagreatway
tosimplifydatabaseaccess—especiallysinceitrequireslittleefforton
yourparttoprovideauserinterfacetodata.


AdditionalTechniques(Chapters26–30)
Inthelastsectionofthebookyou'lllookatawidevarietyofadditional
C#and.NETsubjects.InChapter26you'lllearnmoreabout.NET
assemblies,thebasicbuildingblocksofallsortsof.NETapplications.
InChapter27you'lllookatattributes,apowerfulwaytobothinclude
additionalinformationabouttypesinassemblies,andaddfunctionality
thatwouldotherwisebedifficulttoimplement.
Chapter28dealswithXMLdocumentationandhowyoucan
documentyourapplicationsatthesourcecodelevel.You'llseehowto
addthisinformationandhowtouseandextractit.You'lltakethisto


thepointwhereyou'llbeabletogenerateexpansiveMSDN-style
documentationfromyourcode.
Nextyou'lllookatnetworkinginChapter29,andhowyour
applicationscancommunicatewitheachotherandwithotherservices
acrossvarioustypesofnetworks.Finally,Chapter30comesalmost
asabitoflightrelieffrommanyoftheinvolvedtechniquesyou'llhave
seenearlierinthebookbycoveringthesubjectofgraphics
programmingwithGDI+.You'lllearnhowtomanipulategraphicsand
styleyourapplications,openingthedoortoavastarrayofC#
applicationsandhavingabitoffunalongtheway.


WhatYouNeedtoUseThisBook
ThecodeanddescriptionsofC#andthe.NETFrameworkinthis
bookapplyto.NET2.0.Youdon'tneedanythingotherthanthe
Frameworktounderstandthisaspectofthebook,butmanyofthe
examplesrequireVisualStudio2005(VS).Thereisalsoquitealotof
explanationoftheVSdevelopmentenvironmentwhichmaynotapply

toothertools,suchasVisualC#2005Express.


Conventions
Tohelpyougetthemostfromthetextandkeeptrackofwhat's
happening,we'veusedanumberofconventionsthroughoutthebook.
TryItOut
TheTryItOutisanexerciseyoushouldworkthrough,followingthe
textinthebook.
1. Theyusuallyconsistofasetofsteps.
2. Eachstephasanumber.
3. Followthestepsthroughwithyourcopyofthedatabase.
HowItWorks
AftereachTryItOut,thecodeyou'vetypedwillbeexplainedindetail.

Important Boxeslikethisoneholdimportant,not-to-beforgotten
informationthatisdirectlyrelevanttothesurrounding
text.
Note Tips,hints,tricks,andasidestothecurrentdiscussionare
offsetandplacedinitalicslikethis.
Asforstylesinthetext:
Wehighlightnewtermsandimportantwordswhenwe
introducethem.
Weshowkeyboardstrokeslikethis:Ctrl+A.
Weshowfilenames,URLs,andcodewithinthetextlikeso:
persistence.properties.

Wepresentcodeintwodifferentways:
Incodeexampleswehighlightnewandimportantcodewit




Thegrayhighlightingisnotusedforcodethat'slessi
context,orhasbeenshownbefore.


SourceCode
Asyouworkthroughtheexamplesinthisbook,youmaychoose
eithertotypeinallthecodemanuallyortousethesourcecodefiles
thataccompanythebook.Allofthesourcecodeusedinthisbookis
availablefordownloadat.Onceatthesite,
simplylocatethebook'stitle(eitherbyusingtheSearchboxorby
usingoneofthetitlelists)andclicktheDownloadCodelinkonthe
book'sdetailpagetoobtainallthesourcecodeforthebook.
Note Becausemanybookshavesimilartitles,youmayfindit
easiesttosearchbyISBN;forthisbooktheISBNis0-76457847-2.
Onceyoudownloadthecode,justdecompressitwithyourfavorite
compressiontool.Alternately,youcangotothemainWroxcode
downloadpageat
to
seethecodeavailableforthisbookandallotherWroxbooks.


Errata
Wemakeeveryefforttoensurethattherearenoerrorsinthetextor
inthecode.However,nooneisperfect,andmistakesdooccur.Ifyou
findanerrorinoneofourbooks,likeaspellingmistakeorfaultypiece
ofcode,wewouldbeverygratefulforyourfeedback.Bysendingin
erratayoumaysaveanotherreaderhoursoffrustrationandatthe
sametimeyouwillbehelpingusprovideevenhigherquality

information.
Tofindtheerratapageforthisbook,goto
andlocatethetitleusingtheSearchboxoroneofthetitlelists.Then,
onthebookdetailspage,clicktheBookErratalink.Onthispageyou
canviewallerratathathasbeensubmittedforthisbookandposted
byWroxeditors.Acompletebooklistincludinglinkstoeach'sbook's
errataisalsoavailableatwww.wrox.com/miscpages/booklist.shtml.
Ifyoudon'tspot"your"errorontheBookErratapage,goto
www.wrox.com/contact/techsupport.shtmlandcompletethe
formtheretosendustheerroryouhavefound.We'llcheckthe
informationand,ifappropriate,postamessagetothebook'serrata
pageandfixtheprobleminsubsequenteditionsofthebook.


×