书籍详情

ESSENTIAL C# 2.0(英文版)

ESSENTIAL C# 2.0(英文版)

作者:(美)Mark Michaelis

出版社:人民邮电出版社

出版时间:2007-12-01

ISBN:9787115166876

定价:¥95.00

购买这本书可以去
内容简介
  本书以大量实例,详尽地阐述了C# 2.0的核心特性,指导方针和最佳实践。书中代码采用了专门的格式,并采用 “知识地图”的形式概括出每一章的主要内容。 本书全面讲解了C#语言,读者从中能够学到:C#基本数据类型、值类型、引用类型、类型转换和数组;运算符、控制流、循环、条件逻辑和顺序编程;方法、参数、异常处理和结构化编程;类、遗传、结构接口和面向对象编程;结构良好的类型、运算符重载、命名空间和垃圾回收;泛型、集合和迭代子;映射、属性和声明性编程;线程、同步和多线程模式;互操作性和不安全代码;C#通用语言基础结构(CLI)。 本书内容全面系统,并经过精心编排,相信无论是初学编程的新手、有其他语言编程经验的开发者或是专业C#程序员,阅读本书都将受益匪浅。
作者简介
暂缺《ESSENTIAL C# 2.0(英文版)》作者简介
目录
1 Introducing C# 1
 Hello, World 2
  Compiling and Running the Application 3
  Managed Execution and the Common Language Infrastructure 4
 C# Syntax Fundamentals 7
  C# Keywords 7
  Type Definition 9
  Main 10
  Statements and Statement Delimiters 12
  Whitespace 13
 Working with Variables 14
  Data Types 15
  Declaring a Variable 16
  Assigning a Variable 16
  Using a Variable 18
 Console Input and Output 18
  Getting Input from the Console 18
  Writing Output to the Console 20
 Comments 22
 Common Intermediate Language and ILDASM 25
2 Data Types 29
 Fundamental Numeric Types 30
  Integer Types 30
  Floating-Point Types (float, double) 31
  Decimal Type 32
  Literal Values 33
 More Fundamental Types 38
  Boolean Type (bool) 38
  Character Type (char) 39
  Strings 41
 null and void 49
  null 49
  The void Nontype 50
 Categories of Types 50
  Value Types 50
  Reference Types 51
 Nullable Modifier 53
 Conversions between Data Types 53
  Explicit Cast 54
  Implicit Cast 57
  Type Conversion without Casting 58
 Arrays 60
  Declaring an Array 60
  Instantiating and Assigning Arrays 61
  Using an Array 65
  Strings as Arrays 71
  Common Errors 73
3 Operators and Control Flow 77
 Operators 78
  Plus and Minus Unary Operators (+, -) 78
  Arithmetic Binary Operators (+, -, *, /, %) 79
  Parenthesis Operator 86
  Assignment Operators (+=, -=, *=, /=, %=) 87
  Increment and Decrement Operators (++, --) 88
  Constant Expressions (const) 92
 Introducing Flow Control 92
  if Statement 96
  Nested if  97
 Code Blocks ({}) 99
 Scope 101
 Boolean Expressions 102
  Relational and Equality Operators 103
  Logical Boolean Operators 104
  Logical Negation Operator (!) 106
  Conditional Operator (?) 107
 Bitwise Operators (  ,   , |, &, ^, ~) 108
  Shift Operators (  ,   ,   =,   =) 109
  Bitwise Operators (&, |, ^) 110
  Bitwise Assignment Operators (&=, |=, ^=) 112
  Bitwise Complement Operator (~) 113
 Control Flow Statements, Continued 113
  The while and do/while Loops 113
  The for loop 116
  The foreach Loop 119
  The switch Statement 122
 Jump Statements 124
  The break Statement 124
  The continue Statement 127
  The goto Statement 128
 C# Preprocessor Directives 130
  Excluding and Including Code (#if, #elif, #else, #endif) 131
  Defining Preprocessor Symbols (#define, #undef) 132
  Emitting Errors and Warnings (#error, #warning) 133
  Turning Off Warning Messages (#pragma) 134
  nowarn: warn list  Option 134
  Specifying Line Numbers (#line) 135
  Hints for Visual Editors (#region, #endregion) 135
4 Methods and Parameters 139
 Calling a Method 140
  Namespace 142
  Type Name 144
  Scope 144
  Method Name 145
  Parameters 145
  Method Return 145
  Statement versus Method Call 146
 Declaring a Method 146
  Parameter Declaration 148
  Method Return Declaration 149
 The using Directive 151
  Aliasing 154
 Returns and Parameters on Main() 155
 Parameters 158
  Value Parameters 158
  Reference Parameters (ref) 160
  Output Parameters (out) 161
  Parameter Arrays (params) 163
 Recursion 166
 Method Overloading 169
 Basic Error Handling with Exceptions 171
  Trapping Errors 173
  Reporting Errors Using a throw Statement 181
5 Classes 185
 Defining and Instantiating a Class 189
 Instance Fields 193
  Declaring an Instance Field 193
  Accessing an Instance Field 194
 Instance Methods 195
 Using the this Keyword 196
 Access Modifiers 202
 Constructors 204
  Declaring a Constructor 205
  Default Constructors 206
  Overloading Constructors 208
  Calling Another Constructor Using this 209
 Static 211
  Static Fields 212
  Static Methods 215
  Static Constructors 215
  Static Classes 216
 const and readonly Modifiers 218
  const 218
  readonly 219
 Properties 220
  Declaring a Property 221
  Naming Conventions 224
  Static Properties 225
  Using Properties with Validation 225
  Read-Only and Write-Only Properties 227
  Access Modifiers on Getters and Setters 228
  Properties as Virtual Fields 229
  Properties and Method Calls Not Allowed as ref or out Parameter Values 232
 Nested Classes 232
 Partial Classes 234
6 Inheritance 237
 Derivation 238
  Casting between Base and Derived Types 241
  Support for Parameter Covariance and Contravariance 243
  private Access Modifier 244
  protected Access Modifier 245
  Single Inheritance 246
  Sealed Classes 250
 Overriding the Base Class 250
  virtual Modifier 251
  new Modifier 256
  sealed Modifier 260
  base Member 261
  Constructors 262
 Abstract Classes 263
 Everything Ultimately Derives from System.Object 268
 Verifying the Underlying Type with the is Operator 270
 Conversion Using the as Operator 271
7 Interfaces 273
 Introducing Interfaces 274
 Polymorphism through Interfaces 275
 Interface Implementation 279
  Explicit Member Implementation 281
  Implicit Member Implementation 282
  Explicit versus Implicit Interface Implementation 283
 Casting between the Implementing Class and Its Interfaces 284
 Interface Inheritance 285
 Multiple Interface Inheritance 287
 Implementing Multiple Inheritance via Interfaces 288
 Versioning 291
 Interfaces Compared with Classes 293
8 Value Types 297
 Structs 298
  Initializing structs 302
  Using the default Operator 304
  Inheritance and Interfaces with Value Types 304
 Boxing 305
 Enums 311
  Type Compatibility between Enums 315
  Converting between Enums and Strings 315
  Enums as Flags 316
9 Well-Formed Types 323
 Overriding object Members 323
  Overriding ToString() 324
  Overriding GetHashCode() 324
  Overriding Equals() 326
  Guidelines for Implementing Equality 333
 Operator Overloading 334
  Comparison Operators (==, !=,  ,  ,  =,  =) 334
  Binary Operators (+, -, *, /, %, &, |, ^,   ,   ) 335
  Combining Assignment with Binary Operators (+=, -=, *=, /=, %=, &=...) 337
  Conditional Logical Operators (&&, ||) 337
  Unary Operators (+, -, !, ~, ++, --, true, false) 338
  Conversion Operators 339
  Guidelines for Conversion Operators 340
 Referencing Other Assemblies 341
  Changing the Assembly Target 342
  Encapsulation of Types 343
  Referencing an Assembly 345
 Defining Namespaces 346
  Namespace Alias Qualifier 348
 XML Comments 349
  Associating XML Comments with Programming Constructs 350
  Generating an XML Documentation File 352
 Garbage Collection 353
  Weak References 355
 Resource Cleanup 356
  Finalizers 357
  Deterministic Finalization with the using Statement 359
  Garbage Collection and Finalization 362
  Resource Utilization and Finalization Guidelines 363
10 Exception Handling 365
 Multiple Exception Types 365
 Catching Exceptions 367
 General Catch Block 368
 Guidelines for Exception Handling 371
 Defining Custom Exceptions 373
  
11 Generics 379
 C# without Generics 380
 Introducing Generic Types 385
  Using a Generic Class 385
  Defining a Simple Generic Class 387
  Benefits of Generics 388
  Type Parameter Naming Guidelines 389
  Generic Interfaces and Structs 389
  Defining a Constructor and a Finalizer 392
  Specifying a Default Value 393
  Multiple Type Parameters 394
  Nested Generic Types 395
  Type Compatibility between Generic Classes with Type-Compatible Type Parameters 396
 Constraints 396
  Interface Constraints 400
  Base Class Constraints 401
  struct/class Constraints 402
  Multiple Constraints 403
  Constructor Constraints 404
  Constraint Inheritance 405
 Generic Methods 409
  Type Inferencing 411
  Specifying Constraints 412
 Generic Internals 413
  Instantiating Generics Based on Value Types 415
  Instantiating Generics Based on Reference Types 416
12 Collections 419
 Primary Collection Classes 420
  List Collections: List T  and ArrayList 420
  Dictionary Collections: Dictionary TKey, TValue  and Hashtable 425
  Sorted Collections: SortedDictionary TKey, TValue  and SortedList T  429
  Stack Collections: Stack T  and Stack 431
  Queue Collections: Queue T  and Queue 432
  Linked Lists: LinkedList T  433
 Introducing Collection Class Interfaces 433
  IList T  versus IDictionary TKey, TValue  434
  IComparable T  435
  ICollection T  438
  Iterating Using a foreach Loop 438
 Providing an Index Operator 444
 Returning Null or an Empty Collection 448
 Iterators 448
  Defining an Iterator 449
  Iterator Syntax 450
  Yielding Values from an Iterator 451
  Iterators and State 453
  More Iterator Examples 455
  Placing a yield return within a Loop 456
  Canceling Further Iteration: yield break 459
  Creating Multiple Iterators in a Single Class 461
  yield Statement Characteristics 462
13 Delegates and Events 465
 Method Pointers 466
  Defining the Scenario 466
  Delegate Data Types 468
  Delegate Internals 469
  Defining a Delegate Type 470
  Instantiating a Delegate 471
  Anonymous Methods 475
  Outer Variables 479
 Multicast Delegates and the Observer Pattern 482
  Coding the Observer Pattern with Delegates 482
  Sequential Invocation 490
 Events 496
  Why Events? 496
  Declaring an Event 498
  Coding Conventions 500
  Generics and Delegates 501
  Customizing the Event Implementation 505
14 Reflection and Attributes 509
 Refiection 510
  Accessing Metadata Using System.Type 511
  Member Invocation 513
  Refiection on Generic Types 517
 Attributes 520
  Custom Attributes 524
  Looking for Attributes 525
  Initializing an Attribute through a Constructor 526
  System.AttributeUsageAttribute 531
  Named Parameters 532
15 Multithreading 549
 Running and Controlling a Separate Thread 552
  Starting a Thread 553
  Thread Management 555
 Passing Parameters to Threads 557
 Thread Pooling 561
 Unhandled Exceptions 563
 Synchronization 565
  Synchronization Using Monitor 568
  Using the lock Keyword 570
  Choosing a lock Object 571
  Why to Avoid Locking on this and typeof(type) 572
  Declaring Fields as volatile 573
  Using the System.Threading.Interlocked Class 573
  Event Notification with Multiple Threads 575
  Synchronization Design Best Practices 576
  More Synchronization Types 578
 Timers 584
16 Multithreading Patterns 591
Asynchronous Results Pattern 592
  Introducing the Asynchronous Results Pattern 593
  Passing Data to and from an Alternate Thread 595
  Receiving Notification of Thread Completion 600
  Passing Arbitrary State 603
 Asynchronous Results Conclusions 605
  Background Worker Pattern 606
  Establishing the Pattern 609
  Exception Handling 610
Windows Forms 611
17 Platform Interoperability and Unsafe Code 615
 Platform Invoke 616
  Declaring External Functions 617
  Parameter Data Types 618
  Using ref Rather Than Pointers 619
  Using StructLayoutAttribute for Sequential Layout 620
  Error Handling 621
  Using SafeHandle 623
  Calling External Functions 626
  Simplifying API Calls with Wrappers 628
  Function Pointers Map to Delegates 629
  Guidelines 629
 Pointers and Addresses 630
  Unsafe Code 630
  Pointer Declaration 632
  Assigning a Pointer 634
  Dereferencing a Pointer 636
  Accessing the Member of a Referent Type 638
18 The Common Language Infrastructure 641
 Defining the Common Language Infrastructure (CLI) 642
 CLI Implementations 643
 C# Compilation to Machine Code 644
 Runtime 647
  Garbage Collection 647
  Garbage Collection on .NET 648
  Type Safety 649
  Code Access Security 650
  Platform Portability 650
  Performance 651
 Application Domains 652
 Assemblies, Manifests, and Modules 653
 Common Intermediate Language (CIL) 656
 Common Type System (CTS) 656
 Common Language Specification (CLS) 657
 Base Class Library (BCL) 658
 Metadata 658
A Downloading and Installing the C# Compiler and the CLI Platform 663
B Complete Source Code Listings 667
C C# 2.0 Topics 693
Index 697
猜您喜欢

读书导航