YOMEDIA
ADSENSE
Apress - Accelerated C#_10
86
lượt xem 15
download
lượt xem 15
download
Download
Vui lòng tải xuống để xem tài liệu đầy đủ
Tham khảo tài liệu 'apress - accelerated c#_10', công nghệ thông tin, cơ sở dữ liệu phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả
AMBIENT/
Chủ đề:
Bình luận(0) Đăng nhập để gửi bình luận!
Nội dung Text: Apress - Accelerated C#_10
- ■ INDEX partial, 77–79 global, 37 sealed, 131 importing, 490 static, 49–50 side effects, avoiding, 496 virtual, 67–69, 128–132 using, 37–38, 490 Microsoft Foundation Classes (MFC), 149 naming conventions Microsoft Windows Internals, Fourth Edition: for culture names, 219 Microsoft Windows Server 2003, for exceptions, 206 Windows XP, and Windows 2000 for interfaces, 139, 157 (Russinovich & Solomon), 401 for methods, 138 Min method, 566 generic type parameter placeholders and, mirror overload, 168 311 Modern C++ Design: Generic Programming and namespaces and, 36 Design Patterns Applied Nathan, Adam, 9 (Alexandrescu), 325 native applications, 2, 11 Monitor class, 249, 378, 387–396, 401–402 native code, 2 Monitor.Enter method, 390, 393 nested classes, 71–74 Monitor.Exit method, 390, 393 .NET Monitor.Pulse method, 393, 396 exception handling and, 116 Monitor.Wait method, 368, 393 threading and, 361–378 Mono project, 2 .NET 2.0 MoveNext method, 267, 269 catch clauses and, 185 mscorlib assembly, 4 unhandled exceptions in, 182–183 MTAThreadAttribute attribute, 377 .NET and COM: The Complete Interoperability MulticastDelegate class, 280 Guide (Nathan), 9 multidimensional arrays, 251–255 The .NET Developer’s Guide to Windows multiple assemblies, 12 Security (Brown), 9 multiple inheritance, 132 .NET Framework Security (LaMacchia), 9, 272 MultiplyBy2 method, 294 new constraints, 330–331 MultiplyBy4 method, 294 new keyword, 74, 84, 139 multithreaded apartment (MTA), 377 class types and, 103–104 multithreading. See threading member hiding and, 67, 74, 141, 149 mutating operands, avoiding, 167 method overrides and, 129–131 Mutex class, 378 uses, 103 vs. Monitor class, 388 value types and, 103 Mutex objects, 401, 402 new operator, 27, 317 MyClass< Stack >, 311 nondeterministic destruction, 115 MyClass, 313 nondeterministic finalization, 118 MyClass, 312 NonGeneric method, 311 MyCollection, 307 nongeneric types, 311 MyCollection, 307, 316 non-nested classes, 71 MyCollection, 307 Non-Virtual Interface (NVI) pattern, 431–434 MyContainer, 316 NotSupportedException, 262, 269 MyContainer, 316, 322 null values, 323–324 MyNestedClass, 313 nullable types, 323–324 Nullable, 323–324 NullReferenceException, 182, 192, 291 ■N NVI pattern, 431–434 name conflicts, 81 named arguments, 7, 125–128 ■O namespace aliasing, 38 namespaces, 4, 35–38 Object class, 101–103, 154, 243 coding practices, 496–497 object initializers, 6 declaring, 36–37 nesting, 92 620
- ■ INDEX syntax, 91–94 dynamic, 592–594 uses, 91 overloadable operators. See operator object keyword, 101 overloading object references, 44 overloaded constructors, 49 object type, 22 overloading methods, 123, 126 Object.Equals method, 103, 450–457 override keyword, 129 Object.ToString method, 218, 221, 225 ObjectDisposedException, 441 ■P Object-Oriented Analysis/Design (OOA/D), 141 P/Invoke, 201–205 object-oriented methodologies, 25 Parallel class, 420–425 object-oriented programming, 544 Parallel Extensions, 417–418 objects, 43 Parallel.For method, 422 copies and, 434–440 Parallel.Invoke, 425–426 C# vs. C++, 27, 430 param arrays, 123 creating, 103–113, 430 param parameters, 123 destroying, 44, 113–116 parameter binding, 300–303, 538 disposable, 116–119 ParameterExpression, 527 internal state of, 43 ParameterizedThreadStart delegate, 365 memory allocation for, 113 parameters memory associated with, 44 order, 167–168 terminology and, 26 out, 122–123 On method, 291 params keyword, 123 OOA/D (Object-Oriented Analysis/Design), 141 parentheses, 235 open instance delegates, 285–288 partial classes, 76–77 open types. See generic types partial keyword, 77 operands, 167 partial methods operation chaining, 502–503 described, 77–79 operator overloading, 18, 165–179 restrictions, 77 addition operator, 168–169 uses, 6, 78 Boolean operators, 176–179 partial types, 6 mutating operands and, 167 partially named assemblies, 12 operators for, 169–179 PassAsOutParam() method, 123 parameter order and, 167–168 PassByRef() method, 121 reasons not to use, 165 PassByValue() method, 121 semantics and, 165 patterns, design, 137 types and formats, 165–166 PE (Portable Executable) file format, 2 Visual Basic and, 457 performance, collection types and, 262–263 operator precedence, 18–20 phantom method, 594 operators PlayEvent identifier, 291 applying to parameterized types, 347–357 polymorphism, 44, 63–65, 129 declaring, C# vs. C++, 166 Portable Executable (PE) file format, 2 optimizations, 11 positional arguments, 126 optional arguments, 124–125 postfix operator (++), 167 orderby clause (LINQ), 553–554, 563–565 prefix operator (--), 167 ordering of object instance creation, 109–113 PrepareConstrainedRegions method, 199 Ordinal property, 228 primary constraints, 330 OrdinalIgnoreCase property, 228 Primary Interop Assemblies (PIA), 578 OS threads, 361 printf method, vs. String.Format method, 222 out keyword, 122, 337 Priority property, 363 out parameters, 85, 122–123 private access modifier, 60 OutOfMemoryException, 199–201 private assemblies, 13 overflow errors, 174 private field modifier, 46 overload resolution, 592 621
- ■ INDEX private virtual methods, C++ and, 433 readonly field modifier, 47 Pro C# 2005 and the .NET 2.0 Platform, Third readonly fields, 48 Edition (Troelsen), 9 readonly properties, 47, 53 ProcessResults type, 282 readonly public field, 53 profile-guided optimizations, 11 rectangular arrays, 251–253 projection operators, 546 recursion, anonymous, 540–541 projector clause (LINQ). See group clause recursive computations, 421 (LINQ); select clause (LINQ) ref arguments, 120–122 properties ref keyword, 121 accessors and, 53 ref parameters, 121–123 auto-implemented. See auto-implemented reference type variables, 22–23, 27, 44 properties reference types, 3, 22–23, 26–27, 44 declaring, 51 canonical forms and, 429–476 public, 52 checklist for, 429, 485–486 read-only, 47, 53 convertability and, 247–248 reserved names and, 81 default values, 27 uses, 51 described, 94 write-only, 53 explicit interface implementation and, 154 protected access modifier, 60 identity equality and, 451–453 protected field modifier, 46 immutability and, 473, 476 protected internal access modifier, 60 overriding Object.Equals method for, 454– protected virtual methods, 291 457 public access modifier, 60 sealed classes and, 430–431 public field modifier, 46 type conversion, 30 publish/subscribe, 289 type safety and, 469–473 Pulse method, 393, 396 referenced assemblies, 14 ReferenceEquals method, 456 referential equality, 456 ■Q reflection, 14, 270, 272 query expressions, 544–546 Regex class, 232–242 keywords, 549–550 Regex.Replace method, 238 query variables (LINQ), 546, 562, 563, 564 RegexOptions, 240–242 Queryable class, 565 RegionInfo types, 219 Queryable.Where method, 553 Register method, 220 Queue.Clear method, 256 regular expressions Queue class, 344 searching strings with, 232–242 QueueProcessor class, 364 text substitution and, 238–240 QueueUserWorkItem method, 408 regular-expression substitutions, 239 Release method, 402 ReleaseHandle method, 205 ■R ReleaseMutex method, 401 R identifier, 312, 314 ReleaseReaderLock method, 398 RAII (Resource Acquisition Is Initialization), ReliabilityContractAttribute (ListSwap 115, 207, 430 method), 201 range checking, 244 Remove method, 283, 292 Range method, 565 RemoveAll method, 283 range variables (LINQ), 546, 549–550, 562–565 Repeat method, 565 rank, of arrays, 248, 253 Replace method, 234, 240 RankException, 248 reserved member names, 59, 81–82 Rattz, Joseph C., Jr., 576 Reset method, 267–269 read thread mode, 400 ResetAbort method, 368–370 ReaderWriterLock, 397–401 Resource Acquisition Is Initialization (RAII), ReaderWriterLockSlim, 400–401 115, 207, 430 622
- ■ INDEX resources for further reading SerializableAttribute, 206 assembly loading, 13 set accessor, 53 C++ design, 325 Set method, multidimensional array and, 253 CLR, 9 SetMinThreads method, 408 code access security, 272 sets. See HashSet collection class efficiency bottlenecks, 262 SetValue method, multidimensional array and, exception handling, 193 253 exception-neutral code, 196 shallow copies, objects and, 435, 440 hash codes, generating, 459 short type, 21, 24 interface tables, 152 Shutdown method, 396 interface-based programming, 137 single inheritance, 133 libraries, 70 single-threaded apartment (STA), 377 metadata, 15 Singleton design pattern, 159 method tables, 129 Singleton pattern, 80, 314 regular expressions, 232 Skip method (LINQ), 562 types, 273 SkipWhile method (LINQ), 562 Resume method, 372, 379 Sleep method, 368, 371, 379, 383 rethrowing exceptions, 186–187 SMP (symmetric multiprocessing), 381 return statement, 40–41 SOA (service-oriented architecture) systems, reverse iterators, 273–277 137 Reverse method, 566 Socket class, 413 RndThreadFunc method, 381, 385 Solomon, David A., 401 rollback behavior, 211–214 SomeFunction() method, 50 rude thread abort, 369 SomeMethod() method, 130 Running state, of threads, 368, 377 SomeOperation() method, 51 Runtime Callable Wrapper (RCW), 578 sortability, 248 RuntimeCompatibilityAttribute, 185 SortedDictionary class, 259, 344 RuntimeHelpers class, 199 SortedList class, 344 RuntimeWrappedException, 185 SortedList class, 344 Russinovich, Mark E., 401 sorting, 554 SortStrategy delegate, 305 specialization, 63 ■S spin locks, 382 safe code, 27 SpinLock class, 385–387 safe points, 372 SpinLock.Enter method, 384 SafeHandle class, 114, 201–205, 407 SpinLockManager, 385 SafeWaitHandle class, 407 SQL, 544–545 sample code Stack.Clear method, 256 complex numbers and, 247–357, 462 Stack class, 344 employee raises, delegates and, 286 StackOverflowException, 198–199 media player, events and, 288–292 standard query operators, 544, 547–548 sbyte type, 21, 24 Start method, 368 sealed classes, 69, 145, 430–431, 495 StartsWith method, 232 sealed keyword, 70, 131, 430 statements, 20 sealed methods, 131 STAThreadAttribute attribute, 377 searchability, 248 static classes, 79–80 select clause (LINQ), 552–555, 563–564 static constructors, 49, 106–109, 314 Sells, Chris, 9, 129 exceptions thrown in, 191–192 semantics, operator overloading and, 165 static field modifier, 46 SemaphoreFullExceptions, 402 static fields, 46 semaphores, 402 static methods, 49–50 semicolon, 20 static modifier, 79 Serializable attribute, 45 static receiver, 582 623
- ■ INDEX StaticCompute method, 284 switch statement, 39 STL (Standard Template Library) symmetric multiprocessing (SMP), 381 programming, 300, 502, 529, 538, 576 sync events, 404 Stop method, 277 synchronization, 249 Strategy pattern, 292, 304–305 collections and, 257 Strategy property, 294 enumerators, 269 streams. See iterators, over infinite sets Interlocked class and, 379–385 StreamWriter, 384 locking objects and, 396–402 String class, 215, 227, 229, 438 Monitor class and, 387–396 string literals, 216–217 semaphores and, 402–404 string type, 22 SpinLock class and, 385–387 String.Compare method, 227 threading and, 378–407 String.Copy method, 438 WaitHandle and, 405–407 String.Format method, 222–224 synchronized field, 270 String.Intern method, 217 Synchronized method, 257 String.Join method, 575 SyncRoot property, 257, 267 StringBuilder class, 230–232 syntax, 17–41 StringBuilder.AppendFormat method, 224 sysglobl.dll assembly, 220 StringComparer class, 227 system heap, 44 StringComparer.Create method, 228 System namespace, 21, 35 StringComparison enumeration, 227 System Performance Monitor (perfmon), 423 strings, 215 System.Activator namespace, 358 comparing, 227– 228 System.Array, 243, 253 converting, 467 vectors and, 250 floating-point values, converting to, 219 System.Array interface, 248 format, 465 System.Collections namespace, 255, 310 format specifiers and, 217–228, 465 System.Collections.Concurrent namespace, 421 format, 221–227 System.Collections.Generic namespace, 255, memory issues, 230 344–345 outside sources and, 228–230 System.Collections.ObjectModel namespace, overview, 215, 216 255–256, 260–262 searching with regular expressions, 232–242 System.Collections.Specialized namespace, 255 verbatim, 217 System.Console class, 80 strong typing. See also variables, implicitly System.Convert class, 231 typed local System.Double namespace, 221 strongly named assemblies, 12–13 System.Dynamic.DynamicObject, 585 strongly typed languages, 17–18, 469 System.Exception exception, 185, 188, 206–207 struct constraints, 330–331 System.Globalization namespace, 219 struct declarations, 21 System.Int32, 150 struct keyword, 22–23, 44, 82 System.Int32.MaxValue, 231 struct member definitions, access modifiers, 60 System.Ling namespace, 545 structs System.Ling.Enumerable class, 544, 566 contents, 82 System.Ling.Expressions namespace, 518, 524, generic, 311–314 528 interfaces and, 87 System.Ling.Expressions.Expression, 524 SubmitWorkItem method, 396 System.Ling.Queryable class, 503, 544, 566 Sum method, 566 System.Monitor class, 249 SuppressFinalize() method, 118, 446 System.Object, 101–103, 154, 243 Suspend method, 369, 372, 379 System.Object types, 550 Suspended state, of threads, 369 System.OutOfMemoryException, 103 SuspendRequested state, of threads, 369 System.String class, 215, 227, 229, 438 Sutter, Herb, 196 System.Text.Encoding class, 216, 228–230 swap operations, 198 System.Thread class, 363 624
- ■ INDEX System.Threading namespace, 198 exceptions, 400 System.Threading.Semaphore class, 402 foreground/background threads and, 372– System.Type namespace, 357 373 System.Type object, 14 halting, 371–372 System.TypeInitializationException, 191 locking objects and, 396–402 System.ValueType, 82 Monitor class and, 387–396 .NET and, 361–378 passing data to, 363–365 ■T recursion, 400 T identifier, 312, 314 semaphores and, 402–404 Take extension (LINQ), 562, 565, 573–574 SpinLock class and, 385–387 TakeWhile method (LINQ), 562 states of, 366–369, 400 Task class, 418–420 synchronization and, 378–407 Task Parallel Library (TPL), 417–418 terminating/halting threads and, 369–372 Parallel class, 420–425 unmanaged threads and, 377–378 Task class, 418–420 WaitHandle and, 405–407 TaskFactory.StartNew() method, 419 waiting for exiting, 372 TBL (Type Library), 14 waking, 371–372 template metaprogramming (C++), 501 Threading.Interlocked class, 379 Template Method pattern, 433 ThreadInterruptedException, 368, 371 ternary operator, 169, 176 thread-local storage, 373–377 TestForEquality method, 452 ThreadPool class, 405, 408 text substitution, 238–240 ThreadPool object, 394 ThenBy extension method (LINQ), 554 ThreadPool.QueueUserWorkItem method, 408 this keyword, 49, 51, 74, 85–87, 286 thread-safe collection classes, 426 this parameter, 104 ThreadStart delegate, 362 Thread class, 363 ThreadState enumeration, 368 thread pools, 407–417 ThreadStaticAttribute attribute, 373 asynchronous method calls and, 408–416 throw statement, 40–41, 182 entry, using Parallel.Invoke, 425–426 exception-neutral code and, 194–196 timers and, 416–417 rethrowing exceptions and, 186 Thread.Abort method, 368–370 throwing exceptions, 182–192 Thread.AllocateDataSlot method, 375 thunks, 279 Thread.AllocateNamedDataSlot method, 375 Timer class, 416 Thread.ApartmentState property, 377 System.Threading namespace, 417 Thread.CurrentThread property, 362 System.WindowsForms namespace, 417 Thread.GetHashCode, 363 TimerProc method, 417 Thread.Interrupt method, 368, 371 timers, 416–417 Thread.IsBackground property, 373, 396, 412 TInput placeholder identifier, 317 Thread.Join method, 363, 368 TLSClass, 374 Thread.ManagedThreadId property, 363 TLSFieldClass, 374 Thread.Priority property, 363 ToArray extension method, 575 Thread.ResetAbort method, 368, 370 ToList extension method, 565 Thread.Resume method, 379 ToString method, 102, 463–467 Thread.Sleep method, 368, 371, 379, 383 customized, 218 Thread.Suspend method, 369, 372, 379 IFormattable class, 218–219, 224–225 ThreadAbortException, 183, 199, 368–371 IFormatter class, 223 ThreadFunc method, 362 Object class, 225 threads/threading, 361–427 String.Format method and, 223 background, 372–373 TOutput placeholder identifier, 317 concurrent programming and, 417–426 TPL. See Task Parallel Library creating, 362, 363 transforms, 497–501 events and, 404–405 translating exceptions, 187–188 625
- ■ INDEX Troelsen, Andrew, 9 ushort type, 21, 24 try statement, 183–184 using keyword, 4, 21, 118–119, 212 exception-neutral code and, 193 deterministic destruction and, 443 try/catch statement, 20 disposable objects and, 442 try/finally statement, 21, 118 extension methods and, 490 TryGetValue method, 259 namespaces and, 37 type casting, 173 using statement, 21 type conversion, 30 UTF-16 Unicode character strings, 216 array covariance, 30–31 boxing conversion, 31 ■V dynamic, 590–592 Validate method, 207 explicit, 44 value arguments, 120 generic, 320–321, 347–357 value equality, 450, 454 implicit, 44, 63–65 value keyword, 292 Type Library (TLB), 14 value type definitions, 82–88 type safety, 309–311 constructors, 82–84 reference types and, 469–473 finalizers, 87 value types and, 482–484 interfaces, 87 TypeConverter class, 468 this keyword, 85–87 TypeInitializationException, 191, 206 value types, 3, 22–27 typeof keyword, 14, 358 canonical forms and, 476–484 types, 3, 21–35 checklist for, 429, 486–487 anonymous, 88–91 definition, 44 canonical forms and, 429–487 described, 94 convertibility, 467–469 Equals override and, 477–481 convertibility and, 247–248 explicit interface implementation and, 154– creating own, 43 156 generic, 34–35 interface implementation and, 150, 481 testing, 32–34 new keyword for, 103 See also built-in types type safety and, 482–484 value equality and, 450 ■U values, terminology and, 26 uint type, 21, 24 ValueType class, 481 ulong type, 21, 24 ValueType.Equals method, 454 unary operators var keyword, 28, 89 list, 170 VarArgs() method, 123 overloading, 169 variable capture, 297–300, 533–538 parameters and, 166 variables, 21–35 UnaryExpression, 527 default initialization, 27 unbound delegates, 285–288 implicit typing, 526 unboxing, 94–101 implicitly typed local, 6, 28–29 undefined behavior exception, 115 reference type, 22–23, 27, 44 unhandled exceptions, 115, 182, 183 type testing, 32–34 UnhandledExceptionEventArgs, 182 variance, 7, 332–334 unheld thread mode, 400 delegates and, 340–344 unmanaged threads, 377–378 rules, 335 unsafe (unmanaged) code techniques, 26 vectors, vs. arrays, 249, 251 unspeakable field names, 89 verbatim strings, 217 Unstarted state, of threads, 368 Vermeulen, Allan, 366 upgradeable thread mode, 400 versioning, 13, 156–157 UpgradeToWriterLock method, 399 Virtual Execution Systems (VESs), 2, 9 user-defined value types, 23 virtual keyword, 129, 148 626
- ■ INDEX virtual methods, 67–69, 128–132 Web Services Description Language (WSDL), overriding, 127–131 8139 Visitor pattern, 511–515 where clause (LINQ), 552–554, 563–564 Visual Basic, collection types and, 260 where keyword, 329 Vlissides, John, 137, 433, 511 while statement, 20, 39 volatile field modifier, 48 Win32 functions, 204 vtables, vs. interface tables, 152 Win32 Synchronization objects, 405 write thread mode, 400 write-only properties, 53 ■W Wait method, 368, 393 ■X WaitAll method, 406 WaitAny method, 406 xperf, 422, 423 WaitHandle class, 402, 405, 407 WaitHandle.WaitAll method, 406 ■Y WaitHandle.WaitAny method, 406 Y fixed-point combinators, 541 WaitHandle.WaitOne method, 404 ”Yet Another Language Geek” blog, 511 WaitOne method, 401–406 yield blocks, 268–277, 562–563 WaitSleepJoin state, of threads, 368 yield break statement, 270 waking threads, 371 yield keyword, 262, 268, 317 627
ADSENSE
CÓ THỂ BẠN MUỐN DOWNLOAD
Thêm tài liệu vào bộ sưu tập có sẵn:
Báo xấu
LAVA
AANETWORK
TRỢ GIÚP
HỖ TRỢ KHÁCH HÀNG
Chịu trách nhiệm nội dung:
Nguyễn Công Hà - Giám đốc Công ty TNHH TÀI LIỆU TRỰC TUYẾN VI NA
LIÊN HỆ
Địa chỉ: P402, 54A Nơ Trang Long, Phường 14, Q.Bình Thạnh, TP.HCM
Hotline: 093 303 0098
Email: support@tailieu.vn