在好例子网,分享、交流、成长!
您当前所在位置:首页C# 开发实例C#语言基础 → [Programming C# 5.0].2012.英文版

[Programming C# 5.0].2012.英文版

C#语言基础

下载此实例
  • 开发语言:C#
  • 实例大小:19.37M
  • 下载次数:5
  • 浏览次数:38
  • 发布时间:2022-01-20
  • 实例类别:C#语言基础
  • 发 布 人:bighero3
  • 文件格式:.pdf
  • 所需积分:2

实例介绍

【实例简介】[Programming C# 5.0].2012.英文版

【实例截图】

from clipboard

【核心代码】

Table of Contents
Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii
1. Introducing C#. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Why C#? 1
Why Not C#? 3
C#’s Defining Features 5
Managed Code and the CLR 7
Generality Trumps Specialization 9
Asynchronous Programming 10
Visual Studio 10
Anatomy of a Simple Program 13
Adding a Project to an Existing Solution 15
Referencing One Project from Another 15
Writing a Unit Test 17
Namespaces 20
Classes 24
Program Entry Point 25
Unit Tests 26
Summary 27
2. Basic Coding in C#. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Local Variables 30
Scope 35
Statements and Expressions 39
Statements 39
Expressions 40
Comments and Whitespace 46
Preprocessing Directives 48
Compilation Symbols 48
#error and #warning 49
v
#line 50
#pragma 50
#region and #endregion 51
Intrinsic Data Types 51
Numeric Types 52
Booleans 61
Strings and Characters 62
Object 62
Operators 62
Flow Control 68
Boolean Decisions with if Statements 68
Multiple Choice with switch Statements 70
Loops: while and do 72
C-Style for Loops 73
Collection Iteration with foreach Loops 75
Summary 76
3. Types. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
Classes 77
Static Members 80
Static Classes 82
Reference Types 83
Structs 89
When to Write a Value Type 93
Members 98
Fields 98
Constructors 100
Methods 108
Properties 114
Indexers 117
Operators 119
Events 122
Nested Types 122
Interfaces 124
Enums 126
Other Types 129
Anonymous Types 129
Partial Types and Methods 130
Summary 131
4. Generics. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
Generic Types 134
vi | Table of Contents
Constraints 136
Type Constraints 137
Reference Type Constraints 139
Value Type Constraints 142
Multiple Constraints 142
Zero-Like Values 143
Generic Methods 144
Type Inference 145
Inside Generics 145
Summary 147
5. Collections. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
Arrays 149
Array Initialization 153
Variable Argument Count with the params Keyword 154
Searching and Sorting 155
Multidimensional Arrays 162
Copying and Resizing 166
List<T> 167
List and Sequence Interfaces 170
Implementing Lists and Sequences 174
Iterators 175
Collection<T> 179
ReadOnlyCollection<T> 180
Dictionaries 181
Sorted Dictionaries 184
Sets 185
Queues and Stacks 186
Linked Lists 187
Concurrent Collections 188
Tuples 189
Summary 190
6. Inheritance. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
Inheritance and Conversions 192
Interface Inheritance 194
Generics 195
Covariance and Contravariance 196
System.Object 202
The Ubiquitous Methods of object 202
Accessibility and Inheritance 203
Virtual Methods 204
Table of Contents | vii
Abstract Methods 206
Sealed Methods and Classes 213
Accessing Base Members 214
Inheritance and Construction 215
Special Base Types 220
Summary 221
7. Object Lifetime. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
Garbage Collection 224
Determining Reachability 225
Accidentally Defeating the Garbage Collector 227
Weak References 230
Reclaiming Memory 234
Garbage Collector Modes 240
Accidentally Defeating Compaction 242
Forcing Garbage Collections 245
Destructors and Finalization 246
Critical Finalizers 250
IDisposable 250
Optional Disposal 257
Boxing 257
Boxing Nullable<T> 262
Summary 263
8. Exceptions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265
Exception Sources 267
Exceptions from APIs 268
Exceptions from Your Code 270
Failures Detected by the Runtime 271
Handling Exceptions 272
Exception Objects 273
Multiple catch Blocks 274
Nested try Blocks 275
finally Blocks 277
Throwing Exceptions 278
Rethrowing Exceptions 279
Failing Fast 282
Exception Types 283
Custom Exceptions 285
Unhandled Exceptions 288
Debugging and Exceptions 290
Asynchronous Exceptions 292
viii | Table of Contents
Summary 294
9. Delegates, Lambdas, and Events. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295
Delegate Types 296
Creating a Delegate 297
Multicast Delegates 301
Invoking a Delegate 302
Common Delegate Types 305
Type Compatibility 306
Behind the Syntax 310
Inline Methods 313
Captured Variables 316
Lambdas and Expression Trees 323
Events 324
Standard Event Delegate Pattern 326
Custom Add and Remove Methods 327
Events and the Garbage Collector 330
Events Versus Delegates 332
Delegates Versus Interfaces 333
Summary 333
10. LINQ. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335
Query Expressions 336
How Query Expressions Expand 339
Supporting Query Expressions 341
Deferred Evaluation 345
LINQ, Generics, and IQueryable<T> 348
Standard LINQ Operators 350
Filtering 352
Select 354
SelectMany 357
Ordering 360
Containment Tests 362
Specific Items and Subranges 364
Aggregation 368
Set Operations 372
Whole-Sequence, Order-Preserving Operations 373
Grouping 374
Joins 379
Conversion 381
Sequence Generation 386
Other LINQ Implementations 386
Table of Contents | ix
Entity Framework 387
LINQ to SQL 387
WCF Data Services Client 388
Parallel LINQ (PLINQ) 388
LINQ to XML 388
Reactive Extensions 388
Summary 389
11. Reactive Extensions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 391
Rx and .NET Versions 393
Fundamental Interfaces 395
IObserver<T> 396
IObservable<T> 397
Publishing and Subscribing with Delegates 404
Creating an Observable Source with Delegates 404
Subscribing to an Observable Source with Delegates 407
Sequence Builders 409
Empty 409
Never 409
Return 409
Throw 410
Range 410
Repeat 410
Generate 410
LINQ Queries 411
Grouping Operators 414
Join Operators 415
SelectMany Operator 420
Aggregation and Other Single-Value Operators 420
Concat Operator 422
Rx Query Operators 422
Merge 423
Windowing Operators 424
The Scan Operator 431
The Amb Operator 432
DistinctUntilChanged 433
Schedulers 434
Specifying Schedulers 434
Built-in Schedulers 437
Subjects 438
Subject<T> 438
BehaviorSubject<T> 440
x | Table of Contents
ReplaySubject<T> 440
AsyncSubject<T> 441
Adaptation 441
IEnumerable<T> 441
.NET Events 443
Asynchronous APIs 445
Timed Operations 447
Interval 447
Timer 449
Timestamp 449
TimeInterval 450
Throttle 451
Sample 451
Timeout 451
Windowing Operators 451
Delay 452
DelaySubscription 453
Summary 453
12. Assemblies. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 455
Visual Studio and Assemblies 455
Anatomy of an Assembly 456
.NET Metadata 457
Resources 457
Multifile Assemblies 457
Other PE Features 458
Type Identity 460
Loading Assemblies 462
Explicit Loading 465
The Global Assembly Cache 466
Assembly Names 468
Strong Names 468
Version 471
Culture 476
Processor Architecture 479
Portable Class Libraries 480
Packaged Deployment 482
Windows 8 UI–Style Apps 482
ClickOnce and XBAP 483
Silverlight and Windows Phone Apps 484
Protection 485
Table of Contents | xi
Summary 486
13. Reflection. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 487
Reflection Types 488
Assembly 490
Module 494
MemberInfo 495
Type and TypeInfo 498
MethodBase, ConstructorInfo, and MethodInfo 502
ParameterInfo 504
FieldInfo 505
PropertyInfo 505
EventInfo 505
Reflection Contexts 506
Summary 508
14. Dynamic Typing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 509
The dynamic Type 511
dynamic and Interoperability 513
Silverlight and Scriptable Objects 516
Dynamic .NET Languages 517
Inside Dynamic 518
Restrictions on the dynamic Type 518
Custom Dynamic Objects 520
ExpandoObject 523
Limitations of dynamic 523
Summary 526
15. Attributes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 527
Applying Attributes 527
Attribute Targets 530
Compiler-Handled Attributes 531
CLR-Handled Attributes 536
Defining and Consuming Custom Attributes 543
Attribute Type 544
Retrieving Attributes 546
Summary 548
16. Files and Streams. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 551
The Stream Class 552
Position and Seeking 554
Flushing 555
xii | Table of Contents
Copying 556
Length 556
Disposal 558
Asynchronous Operation 559
Concrete Stream Types 559
Windows 8 and IRandomAccessStream 560
Text-Oriented Types 563
TextReader and TextWriter 564
Concrete Reader and Writer Types 566
Encoding 568
Files and Directories 572
FileStream Class 573
File Class 576
Directory Class 579
Path Class 580
FileInfo, DirectoryInfo, and FileSystemInfo 582
Known Folders 583
Serialization 584
BinaryReader and BinaryWriter 585
CLR Serialization 585
Data Contract Serialization 589
XmlSerializer 592
Summary 593
17. Multithreading. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 595
Threads 595
Threads, Variables, and Shared State 597
The Thread Class 603
The Thread Pool 605
Thread Affinity and SynchronizationContext 610
Synchronization 614
Monitors and the lock Keyword 615
SpinLock 621
Reader/Writer Locks 623
Event Objects 624
Barrier 627
CountdownEvent 628
Semaphores 628
Mutex 629
Interlocked 629
Lazy Initialization 632
Other Class Library Concurrency Support 634
Table of Contents | xiii
Tasks 635
The Task and Task<T> Classes 635
Continuations 639
Schedulers 641
Error Handling 642
Custom Threadless Tasks 643
Parent/Child Relationships 645
Composite Tasks 645
Other Asynchronous Patterns 646
Cancellation 647
Parallelism 648
The Parallel Class 648
Parallel LINQ 649
TPL Dataflow 650
Summary 650
18. Asynchronous Language Features. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 651
Asynchronous Keywords: async and await 652
Execution and Synchronization Contexts 656
Multiple Operations and Loops 657
Returning a Task 660
Applying async to Nested Methods 662
The await Pattern 662
Error Handling 667
Validating Arguments 669
Singular and Multiple Exceptions 670
Concurrent Operations and Missed Exceptions 672
Summary 673
19. XAML. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 675
XAML-Based Frameworks 676
WPF 677
Silverlight 678
Windows Phone 7 680
Windows Runtime and Windows 8 UI–Style Apps 680
XAML Basics 682
XAML and XML Namespaces 683
Generated Classes and Codebehind 684
Child Elements 686
Property Elements 687
Event Handling 688
Threading 689
xiv | Table of Contents
Layout 690
Properties 691
Panels 697
ScrollViewer 707
Layout Events 707
Controls 709
Content Controls 709
Slider and ScrollBar Controls 713
Progress Controls 713
List Controls 715
Control Templates 716
UserControls 720
Text 720
Displaying Text 721
Editing Text 723
Data Binding 724
Data Templates 728
Graphics 731
Shapes 731
Bitmaps 732
Media 733
Styles 734
Summary 735
20. ASP.NET. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 737
Razor 738
Expressions 739
Flow Control 741
Code Blocks 742
Explicitly Indicated Content 743
Page Classes and Objects 744
Using Other Components 745
Layout Pages 746
Start Pages 747
Web Forms 748
Server-Side Controls 748
Expressions 754
Code Blocks 754
Standard Page Objects 755
Page Classes and Objects 756
Using Other Components 756
Master Pages 757
Table of Contents | xv
MVC 759
Typical MVC Project Layout 759
Writing Models 766
Writing Views 768
Writing Controllers 770
Handling Additional Input 772
Generating Action Links 775
Routing 775
Summary 780
21. Interoperability. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 781
Calling Native Code 781
Marshaling 782
32-bit and 64-bit 790
Safe Handles 791
Security 793
Platform Invoke 793
Calling Convention 794
Text Handling 795
Entry Point Name 795
COM-Style Return Values 796
Win32 Error Handling 800
COM 800
RCW Lifetime 801
Metadata 803
Scripting 809
Windows Runtime 813
Metadata 813
Windows Runtime Types 813
Buffers 814
Unsafe Code 816
C /CLI and the Component Extensions 818
Summary 818
Index. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 821

实例下载地址

[Programming C# 5.0].2012.英文版

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
;
报警