Académique Documents
Professionnel Documents
Culture Documents
Wouter de Kort
ISBN-13: 978-0-7356-7682-4
First printing: July, 2013
To ensure the ongoing accuracy of this book and its companion content, weve reviewed and
confirmed the errors listed below. If you find a new error, we hope youll report it to us on our
website: www.microsoftpressstore.com/contact-us/errata.
AddthefollowingtotheAssumptionssectionbehindbehindthefirst
sentence:
Toruntheexamplesfromthisbookyoushouldbeabletocreatea
consoleapplicationinVisualStudio.
6 Listing14 RemovethefollowinglinesfromListing14: 10/11/2013
publicstaticvoidThreadMethod(objecto)
{
for(intI=0:I<(int)o;i++)
{
Console.WriteLine("ThreadProc:{0}",I);
Thread.Sleep(0);
}
}
9 1stparagraph Reads:
YoucanusetheThread.CurrentThreadclasstoaskforinformation
aboutthethreadthatsexecuting.
Shouldread:
YoucanusetheThread.CurrentThreadpropertytoaskfor
informationaboutthethreadthatsexecuting.
Lastupdated11/26/2014 Page1of9
Page Location Description Date corrected
18 1stparagraph ChangethefirstlineafterListing118 10/11/2013
afterListing
1.18 Reads:
Becausetheentrymethodofanapplicationcan'tbemarkedasasync,
theexampleusestheWaitmethodinMain.
Shouldread:
Becausetheentrymethodofanapplicationcan'tbemarkedasasync,
theexampleaccessestheResultpropertyintheMainmethodwhich
blocksthecodeuntiltheasyncmethodDownloadContentisfinished.
33 Listing137 ThesecondConsole.WriteLinereads: 8/9/2013
Console.WriteLine("LockedAandB")
Shouldread:
Console.WriteLine("LockedBandA")
39 Listing144 Addthefollowinglineaftertheclosing}ofthewhilestatement: 8/9/2013
thrownewOperationCanceledException();
42 Listing146 ChangeListingtitleto: 8/9/2013
Usingtheequalityoperator
43 Listing150 Changethelistingtitleto: 8/9/2013
ShortcircuitingtheANDoperator
52 Listing169 Changelistingtitleto: 8/9/2013
Implementingaforloopwithawhilestatement
59 Paragraph Reads:
beforeListing Listing179showshowyouwouldwritetheexampleinListing173
179 withnewerlambdasyntax.
Shouldread:
Listing179showshowyouwouldwritetheexampleinListing175
withnewerlambdasyntax.
Lastupdated11/26/2014 Page2of9
Page Location Description Date corrected
80 Listing198 Reads:
protectedOrderProcessingException(SerializationInfoinfo,
StreamingContextcontext)
Shouldread:
protectedEntityOperationException(SerializationInfoinfo,
StreamingContextcontext):base(info,context)
Reads:
publicvoidGetObjectData(SerializationInfoinfo,StreamingContext
context)
{
info.AddValue("OrderId",OrderId,typeof(int));
}
Shouldread:
publicoverridevoidGetObjectData(SerializationInfoinfo,
StreamingContextcontext)
{
base.GetObjectData(info,context);
info.AddValue("entityId",EntityId,typeof(int));
}
82 Objective Objective1.5,question3.AlloccurrencesofLogonFailedinanswerA
review#3 DshouldbechangedtoLogonFailedException.
98 Listing211 Reads: 10/11/2013
this.maximumNumberOfCards=maximumNumberOfCards;
Shouldread:
_maximumNumberOfCards=maximumNumberOfCards;
109 Objective2.2 Reads: 8/9/2013
explicit Whereyoucangoimplicitlyfromaderivedtypetoabasetype,you
conversion needtocastfromaderivedtoabasetype
Shouldread:
Whereyoucangoimplicitlyfromaderivedtypetoabasetype,you
needtocastfromabasetypetoaderivedtype
116 Table23 Changethedescrip oninTable23forthepublicaccessmodiferto: 10/11/2013
None;unrestrictedaccess.
123 Objective Removethecommabetweenprotected,internal. 10/11/2013
summary,5th
bullet Reads:
Theaccessmodifiersarepublic,internal,protected,protected,
internal,andprivate.
Shouldread:
Theaccessmodifiersarepublic,internal,protected,protected
internal,andprivate.
Lastupdated11/26/2014 Page3of9
Page Location Description Date corrected
132 Listing250 ChangethecodeinListing250to: 10/11/2013
classRectangle
{
publicRectangle(intwidth,intheight)
{
Width=width;
Height=height;
}
publicvirtualintHeight{get;set;}
publicvirtualintWidth{get;set;}
publicintArea
{
get{returnHeight*Width;}
}
}
ChangethecodeinListing251to:
privateclassSquare:Rectangle
{
publicSquare(intsize)
:base(size,size)
{
}
publicoverrideintWidth
{
get{returnbase.Width;}
set
{
base.Width=value;
base.Height=value;
}
}
publicoverrideintHeight
{
get{returnbase.Height;}
set
{
base.Height=value;
base.Width=value;
}
}
}
Lastupdated11/26/2014 Page4of9
Page Location Description Date corrected
133 1stsentence Reads: 10/11/2013
ofsection "...thatcanyoucanuseonyourowntypes"
Implementing
standard.NET Shouldread:
Framework "...thatyoucanuseonyourowntypes"
interfaces
141 Paragraph ChangeGetAttributeandGetAttributestoGetCustomAttributeand
belowthe GetCustomAttributesintheparagraphbelowListing262.
listing262
141 Listing262 Reads:
Condi onalA ributecondi onalA ribute=
(Condi onalA ribute)A ribute.GetCustomA ribute(
typeof(Condi onalClass),typeof(Condi onalA ribute));
Shouldread:
Condi onalA ributecondi onalA ribute=
(Condi onalA ribute)A ribute.GetCustomA ributes(
typeof(Condi onalClass),typeof(Condi onalA ribute)).First();
142 Listing266 ChangeAttributeTargets.ClasstoAttributeTargets.Parameterin
Listing266
153 2ndparagraph Reads: 10/11/2013
Idiposable
Shouldread:
Idisposable
Lastupdated11/26/2014 Page5of9
Page Location Description Date corrected
154 Example284 ChangetheImplementingIDisposableandafinalizersectionto: 8/9/2013
ImplementingIDisposableandafinalizer
CreatingyourowncustomtypethatimplementsIDisposableanda
finalizercorrectlyisnotatrivialtask.
Asanexample,supposeyouhaveawrapperclassaroundafile
resourceandanunmanagedbuffer.YouimplementIdisposableso
usersofyourclasscanimmediatelycleanupiftheywant.Youalso
implementafinalizerincasetheyforgettocallDispose.Listing284
showshowtodothis.
LISTING284ImplementingIdisposableandafinalizer.
UsingSystem;
usingSystem.IO;
usingSystem.Runtime.InteropServices;
classUnmanagedWrapper:Idisposable
{
privateIntPtrunmanagedBuffer;
publicFileStreamStream{get;privateset;}
publicUnmanagedWrapper()
{
CreateBuffer();
this.Stream=File.Open("temp.dat",FileMode.Create);
}
privatevoidCreateBuffer()
{
byte[]data=newbyte[1024];
newRandom().NextBytes(data);
unmanagedBuffer=Marshal.AllocHGlobal(data.Length);
Marshal.Copy(data,0,unmanagedBuffer,data.Length)
}
~UnmanagedWrapper()
{
Dispose(false);
}
publicvoidClose()
{
Dispose();
}
publicvoidDispose()
{
Dispose(true);
Lastupdated11/26/2014 Page6of9
Page Location Description Date corrected
System.GC.SuppressFinalize(this);
}
protectedvirtualvoidDispose(booldisposing)
{
Marshal.FreeHGlobal(unmanagedBuffer);
if(disposing)
{
if(Stream!=null)
{
Stream.Close();
}
Thereareacoupleofthingstonoticeaboutthisimplementation:
ThefinalizeronlycallsDisposepassingfalsefordisposing.
TheextradisposemethodwiththeBooleanargumentdoesthereal
work.Thismethodchecksifitsbeingcalledinanexplicitdisposeorif
itsbeingcalledfromthefinalizer:
oIfthefinalizercalledDispose,youonlyreleasetheunmanaged
buffer.TheStreamobjectalsoimplementsafinalizerandthegarbage
collectorwilltakecareofcallingthefinalizeroftheFileStream
instance.Becausetheorderinwhichthegarbagecollectorcallsthe
finalizersisunpredictableyoucantcallanymethodsonthe
FileStream.
OIfDisposeiscalledexplicitly,youalsoclosetheunderlying
FIleStream.Itsimportanttobedefensiveincodingthismethodand
alwayscheckforanysourceofpossibleexceptionsItcouldbethat
Disposeiscalledmultipletimesandthatshouldntcauseanyerrors.
TheregularDisposemethodcallsGC.SuppressFinalize(this)tomake
surethattheobjectisremovedfromthefinalizationlistthatthe
garbagecollectoriskeepingtrackof.Theinstancehasalreadycleaned
upafteritself;soitsnotnecessarythatthegarbagecollectorcallsthe
finalizer.
EXAMTIP
Itsimportanttoknowthedifferencebetweenimplementing
Idisposableandafinalizer.Bothcleanupyourobjectbutafinalizeris
calledbytheGarbageCollectorwhiletheDisposemethodcanbe
calledfromcode.
MOREINFOImplementingIdisposableandafinalizer
FormoreinformationonhowtoimplementIdisposableandafinalizer
see:http://msdn.microsoft.com/enus/library/b1yfkh5e.aspx.
160 Nexttolastline TheparagraphafterListing288reads:
newString("x",10000)
Shouldread:
newString('x',10000)
Lastupdated11/26/2014 Page7of9
Page Location Description Date corrected
161 4thparagraph Reads: 10/11/2013
TextWriter
Shouldread:
TextReader
175 Example11 Removetheline//ThreadProc:10attheendofthelisting. 8/9/2013
189 Listing311 Changelistingtitleto: 8/9/2013
CollapsemultiplespaceswithRegEx
201 Fourth A erLis ng322(4thparagraph)removetheline:Thismeansthat
paragraph youcanchecktodeterminewhethertwoitemsareequalbychecking
theirhashcodes.
226 2ndparagraph Thesentenceshouldread'Youcaninstructthecompiler...' 10/11/2013
under
Managing
program
database...
226 Listing343 ChangethefirstlineofLis ng343to:[DebuggerDisplay("Name=
{FirstName}{LastName}")]
243 3rdbulletof Reads: 10/11/2013
Performance AvergateTimer32
Countertypes
Shouldread:
AverageTimer32
247 Objective3.1 Theextracomma(,)after'theuserentersaninvaliddate'shouldbe 10/11/2013
Review removed.
question1
answerA
247 Within TheanswerforObjective3.1,question1ismissing.Theanswer
Objective3.1: shouldbe:
Review
1.Correctanswer:B
A.Incorrect:TheregularParsemethodwillthrowanexceptionifthe
valuetheuserenteredisnotaDateTime.Thisissomethingyouneed
toexpectwhenyouparseuserinput.UsingTryParseavoidsthe
exception.
B.Correct:TryParseshouldbeusedwhenworkingwithuserinput.
C.Incorrect:Convert.ToDateTimecallsParseinternally.Thiswillthrow
anexceptionwhentheuserinputisnotinthecorrectformat.
D.Incorrect:RegEx.Matchwillsearchtheinputstringforthefirst
matchtothespecifiedregularexpression.Itwon'tconverttheinput
stringtoaDateTime.
248 Objective3.2: Objective3.2questionnumber3shouldhaveCmarkedasIncorrectin
Review#3C theanswerssection.
Lastupdated11/26/2014 Page8of9
Page Location Description Date corrected
249 Objective3.3: MarkanswerDforquestion2ofobjective3.3onpage249ascorrect. 10/11/2013
Review
Question2 Shouldread:
Correct.Stronglynaminganassemblyisrequiredtodeployan
assemblytotheGACwhereitcanbesharedbyallapplications.
259 Paragraph ChangeGetExtensionstoGetExtension
belowthe
listing412
260 InLis ng414,415,418and419replacethe<<characterwith": 10/11/2013
stringpath=@"c:\temp\test.dat";Onpage261inLis ng415
change<MyValue>to"MyValue"Lis ng419change<<Alineof
tekst.>>to"Alineoftext."
286 LISTING443 InLis ng443theline:xmlReader.ReadStartElement("Person"); 10/11/2013
shouldbechangedto:xmlReader.ReadStartElement("person");
Andtheline:xmlReader.ReadStartElement("ContactDetails");
shouldbechangedto:
xmlReader.ReadStartElement("contactdetails");
314 2ndparagraph Reads:
inthechapter ThemostnoticeabledifferenceisthatyouuseDataContractAttribute
"Using insteadofSerializableAttribute.Anotherimportantdifferenceisthat
DataContract" membersarenotserializedbydefault.Youhavetoexplicitlymark
themwiththeDataMemberattribute.
Shouldread:
ThemostnoticeabledifferenceisthatyouuseDataContractAttribute
insteadofSerializableAttribute.IfyouomitboththeDataContractand
DataMemberattribute,yourpublicmembersareserialized.Withthe
DataContractattributeapplied,youhavetospecifywhichmembers
youwanttoserializebyusingtheDataMemberattributeonthem.
330 Answer2D ChangetheexplanationforanswerD,question4.2tothefollowing:
AWebservicewillonlymovetheproblemtoanotherlayerofyour
application.InsidetheWebserviceyoustillhavetousesomekindof
storagetosaveyourapplicationdata.
333 Objective4.5 Onquestion2forObjective4.5,theanswerBshouldberemoved 10/11/2013
bothfromthefirstlineandtheCorrectshouldbechangedto
incorrect.OnlyanswerDiscorrect.
333 Objective4.5: ThefirstanswershouldonlyhaveBmarkedascorrect.Dshouldbe 10/11/2013
Objective incorrect.
review1D
Lastupdated11/26/2014 Page9of9