Howard began his career with Microsoft in 1992 at the company’s New Zealand office, working for the first two years with Windows and compilers on the Product Support Services team and th
Trang 2C# 4.0: The Complete Reference
Trang 3About the Author
Herbert Schildt is a leading authority on C#, C++, C, and Java
His programming books have sold millions of copies worldwide and have been translated into all major foreign languages He is
the author of numerous bestsellers, including Java: The Complete
Reference, C++: The Complete Reference, and C: The Complete Reference,
among many others Although interested in all facets of computing,
his primary focus is computer languages, including compilers, interpreters, and robotic control languages He also has an active interest in the standardization of languages Schildt holds both graduate and undergraduate degrees from the University of Illinois He can be reached at his consulting office at (217) 586-4683
His web site is www.HerbSchildt.com.
About the Technical Editor
Michael Howard is a principal security program manager on
the Trustworthy Computing (TwC) Group’s Security Engineering team at Microsoft, where he is responsible for managing secure design, programming, and testing techniques across the company Howard is an architect of the Security Development Lifecycle (SDL), a process for improving the security of Microsoft’s software Howard began his career with Microsoft in 1992 at the company’s New Zealand office, working for the first two years with Windows and compilers on the Product Support Services team and then with Microsoft Consulting Services, where he provided security infrastructure support to customers and assisted in the design of custom solutions and development of software In 1997, Howard moved to the United States to work for the Windows division on Internet Information Services, Microsoft’s next-generation web server, before moving to his current role in 2000.
Howard is an editor of IEEE Security & Privacy, a frequent
speaker at security-related conferences, and he regularly pub-lishes articles on secure coding and design Howard is the co-author of six security books, including the award-winning
Writing Secure Code, 24 Deadly Sins of Software Security, The Security Development Lifecycle, and his most recent release, Writing Secure Code for Windows Vista.
Trang 4C# 4.0: The Complete Reference
Herbert Schildt
New York Chicago San Francisco Lisbon London Madrid Mexico City
Milan New Delhi San Juan Seoul Singapore Sydney Toronto
Trang 5Copyright © 2010 by The McGraw-Hill Companies All rights reserved Except as permitted under the United States Copyright Act of
1976, no part of this publication may be reproduced or distributed in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the publisher
ISBN: 978-0-07-174117-0
MHID: 0-07-174117-8
The material in this eBook also appears in the print version of this title: ISBN: 978-0-07-174116-3, MHID: 0-07-174116-X
All trademarks are trademarks of their respective owners Rather than put a trademark symbol after every occurrence of a trademarked name, we use names in an editorial fashion only, and to the benefi t of the trademark owner, with no intention of infringement of the trademark Where such designations appear in this book, they have been printed with initial caps
McGraw-Hill eBooks are available at special quantity discounts to use as premiums and sales promotions, or for use in corporate training programs To contact a representative please e-mail us at bulksales@mcgraw-hill.com
All trademarks or copyrights mentioned herein are the possession of their respective owners and McGraw-Hill makes no claim of ownership by the mention of products that contain these marks
Information has been obtained by McGraw-Hill from sources believed to be reliable However, because of the possibility of human or mechanical error by our sources, McGraw-Hill, or others, McGraw-Hill does not guarantee the accuracy, adequacy, or completeness of any information and is not responsible for any errors or omissions or the results obtained from the use of such information
TERMS OF USE
This is a copyrighted work and The McGraw-Hill Companies, Inc (“McGrawHill”) and its licensors reserve all rights in and to the work Use of this work is subject to these terms Except as permitted under the Copyright Act of 1976 and the right to store and retrieve one copy of the work, you may not decompile, disassemble, reverse engineer, reproduce, modify, create derivative works based upon, transmit, distribute, disseminate, sell, publish or sublicense the work or any part of it without McGraw-Hill’s prior consent You may use the work for your own noncommercial and personal use; any other use of the work is strictly prohibited Your right to use the work may be terminated if you fail to comply with these terms
THE WORK IS PROVIDED “AS IS.” McGRAW-HILL AND ITS LICENSORS MAKE NO GUARANTEES OR WARRANTIES AS
TO THE ACCURACY, ADEQUACY OR COMPLETENESS OF OR RESULTS TO BE OBTAINED FROM USING THE WORK, INCLUDING ANY INFORMATION THAT CAN BE ACCESSED THROUGH THE WORK VIA HYPERLINK OR OTHERWISE, AND EXPRESSLY DISCLAIM ANY WARRANTY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE McGraw-Hill and its licensors do not warrant or guarantee that the functions contained in the work will meet your requirements or that its operation will be uninterrupted or error free Neither McGraw-Hill nor its licensors shall be liable to you or anyone else for any inaccuracy, error or omission, regardless of cause, in the work or for any damages resulting therefrom McGraw-Hill has no responsibility for the content of any information accessed through the work Under no circumstances shall McGraw-Hill and/or its licensors be liable for any indirect, incidental, special, punitive, consequential or similar damages that result from the use of or inability to use the work, even if any of them has been advised of the possibility of such damages This limitation of liability shall apply to any claim or cause whatsoever whether such claim or cause arises
in contract, tort or otherwise
Trang 6948 C # 4 0 : T h e C o m p l e t e R e f e r e n c e
Value type(s), 37–38, 117
boxing and unboxing,
315–317
and call-by-reference,
178–183
constraints, 516, 529, 531
default value of, 129, 534
new and, 132–133
null and, 530
and nullable types, 618
passed to methods, 176–177
simple type category of,
37, 38
structures as, 319, 334,
338, 339
structures corresponding to
the built-in numeric, NET,
406–407, 646–664
table of C#, 38
Values property, 822, 832, 834,
846, 858, 860, 862
Values<TValue> property, 846
var keyword, 53, 153, 155
used with queries, 567, 568,
570, 591
Variable(s)
captured, 424–425, 428
const, 632
declaration, 25, 26, 29, 51, 55
definition of, 24
dynamic initialization of,
52–53
implicitly typed, 7, 26, 53–54,
567, 568, 589, 591
initializing, 52–53, 55–56
instance See Instance
variables
local, 51, 54–55
member, 12
names, rules governing,
34–35
outer, 424–425, 428
pointer See Pointer(s)
query, 567, 568, 569, 570
reference See Reference
variable(s) scope and lifetime of, 54–56 static, 213, 214–217
volatile, 632 virtual keyword, 302, 305, 309 Virtual
methods, 299, 302–309, 313, 552–553
properties, 305 Visual Studio IDE (Integrated Development Environment),
14, 15–21, 921, 923 void, 22, 118 methods, returning from, 121–122
volatile modifier, 632 vsvars32.bat file, 15
W
Wait( ), 755–759, 779, 789–791, 792 WaitAll( ), 791
WaitAny( ), 791 WaitForExit( ), 782 WaitForFullGCApproach( ), 684 WaitForFullGCComplete( ), 684 WaitForPendingFinalizers( ), 684 WaitHandle class, 763, 767 WaitOne( ), 763, 766, 767,
770, 772
#warning directive, 463, 468 warning #pragma option, 469 Warth, Chris, 4
Web crawler definition of, 913 example program, 913–916
WebClient class, 896, 897, 916–920
methods, table of synchronous, 918–919 properties, table of, 917
WebException, 905, 917 WebExceptionStatus enumeration, 905 WebHeaderCollection collection, 908 WebRequest class, 897, 898, 899–900, 901–904, 913,
917, 920 methods, table of commonly used synchronous
communication, 899 properties, table of, 900 WebResponse class, 897, 898,
899, 900–904, 905, 908, 913,
917, 920 methods, table of commonly used, 901
properties, table of, 901 where clause, 516, 517, 518, 524,
529, 532, 533
in a LINQ query, 567–568, 571–572
Where( ) extension method, 594, 595–596
while loop, 87, 101–103, 107 Widening conversion, 57–58 Windows, 6, 8, 9, 402 WithCancellation( ), 814 WithDegreeOfParallelism( ), 816 WithExecutionMode( ), 816 Write( ), 26, 372, 374, 379,
385, 393 WriteByte( ), 372, 384, 385 WriteLine( ), 23, 26, 27, 43, 50,
315, 359, 374, 379, 402, 403, 404,
406, 662 and bool values, 45 formatted output version of, 45–48, 715, 716, 723–725 and string objects, 159 using a method within, 124 WriteTimeout property, 373
Trang 7I n d e x 949
X
XML, 565
XML comment, 921
tags, table of, 922
XML file containing,
923–924
XOR (exclusive OR) operator (^)
bitwise, 75, 79–80
logical, 69, 70
Xor( ), 921
Y
yield break statement, 889 contextual keyword, 34, 888 return statement, 888 statements, multiple, 890 Yield( ), 781
Z
Zero field, 657