C# 6.0官方规范:入门与特性详解

需积分: 9 0 下载量 161 浏览量 更新于2024-07-15 收藏 2.98MB PDF 举报
C# 6.0 Draft Specification 是一份详细的官方文档,涵盖了C# 6.0语言的草稿规范。C#是一种简单、现代且面向对象的编程语言,深受C、C++和Java程序员的欢迎。它的设计源于C家族,由ECMA国际标准化为ECMA-334标准,并被ISO/IEC作为ISO/IEC 23270标准认可。Microsoft为.NET Framework提供的C#编译器严格遵循这两个标准。 C# 6.0的关键特性包括: 1. **介绍**:该版本的C#引入了全新的功能,旨在提高开发者的生产力和代码的可读性。它强调了组件导向编程(Component-Oriented Programming),这是现代软件设计中的关键要素。 2. **词法结构**:C# 6.0的语法和符号规则进行了优化,以提供更清晰的代码表示。 3. **基本概念**:如类(class)和结构(struct)的处理,这些是面向对象编程的基础,展示了如何创建对象以及它们之间的关系。 4. **类型系统**:C# 6.0可能引入了新的类型支持,比如泛型和可空引用类型,以增强类型安全性和表达能力。 5. **变量和转换**:可能包含了对隐式类型转换和更智能的类型推断的支持,提高了编码效率。 6. **表达式和语句**:表达式的简化和新语法特性,如null-coalescing operator(条件空合并运算符)和lambda expressions(lambda表达式)。 7. **命名空间和程序集**:命名空间的管理得到了改进,有助于组织和管理大型项目中的代码。 8. **类和结构体**:可能对类的设计和接口的实现提供了新的灵活性和性能优化。 9. **数组和集合**:可能引入了数组的新特性或改进了集合框架,提升数据处理效率。 10. **接口**:接口的使用可能更加简洁,支持更好的多态性和接口实现的扩展。 11. **枚举**:C# 6.0可能提供了更方便枚举值的定义和操作。 12. **委托和事件**:委托和事件处理机制可能得到了增强,以便于创建和管理回调函数和事件驱动的应用。 13. **异常处理**:可能更新了异常处理机制,以提高异常处理的优雅度和效率。 14. **属性**:属性的访问修饰符和属性值的处理可能有所变化,以支持更多的元数据和自定义行为。 15. **不安全代码**:尽管C#是类型安全的语言,但文档中可能讨论了如何在特定条件下允许或控制使用不安全代码。 16. **文档注释**:C# 6.0可能强化了文档注释的标准和工具支持,以生成API文档和提高代码的可维护性。 17. **示例**:最后,文档中包含了一个简单的“Hello, World!”程序,展示了如何在C# 6.0中创建并运行一个基础应用程序。 学习C# 6.0的开发者可以从中了解到新特性的细节,这将有助于他们在实际项目中更好地利用C#的强大功能。
2020-10-31 上传
CLR via C# 第4版 英文PDFKristin, words cannot express how /feel about our life together. cherish our family and all our adventures. I'm filled each day with love for Aidan (age 9)and Grant (age 5), you both have been an inspira- tion to me and have taught me to play and have fun Watching the two of you grow up has been so rewarding and enjoyable for me. am lucky to be able to partake in your lives. love and ap preciate you more than you could ever know Contents at a glance Introduction PART I CLR BASICS CHAPTER 1 The clr's execution model CHAPTER 2 Building, Packaging, Deploying, and Administering Applications and Types 33 chaPTeR 3 Shared Assemblies and Strongly Named Assemblies 65 PART I DESIGNING TYPES CHAPTER 4 Type Fundamentals 91 CHAPTER 5 Primitive, Reference, and Value Types 111 CHAPTER 6 Type and Member Basics 151 CHAPTER 7 Constants and fields 175 chaPTer 8 Methods 181 chaPTer 9 Parameters 209 CHAPTER 10 Properties 227 CHAPTER 11 Events 249 CHAPTER 12 Generics 265 CHAPTER 13 Interfaces 295 PARTⅢ ESSENTIAL TYPES CHAPTER 14 Chars, Strings, and Working with Text 317 CHAPTER 15 Enumerated Types and Bit Flags 361 CHAPTER 16 Arrays 373 CHAPTER 17 Delegates 391 CHAPTER 18 Custom Attributes 421 CHAPTER 19 Nullable value Types 441 PART IV CORE FACILITIES CHAPTER 20 Exceptions and state management 451 CHAPTER 21 The Managed Heap and Garbage Collection 505 CHAPTER 22 CLR Hosting and AppDomains 553 CHAPTER 23 Assembly Loading and reflection 583 CHAPTER 24 Runtime serialization 611 CHAPTER 25 Interoperating with WinRT Components 643 PAR V THREADING ChaPTEr 26 Thread basics 669 CHAPTER 27 Compute-Bound Asynchronous Operations 691 CHAPTER 28 IyO-Bound Asynchronous Operations 727 CHAPTER 29 Primitive thread Synchronization Constructs 757 CHAPTER 30 Hybrid Thread Synchronization Constructs 789 Index 823 Contents at a glance Contents Introduction XX PART CLR BASICS Chapter 1 The Clrs Execution Model 3 Compiling Source Code into Managed Modules Combining managed modules into assemblies Loading the Common Language Runtime 8 Executing Your Assembly's Code 11 IL and∨ erification 16 Unsafe Code The Native Code generator tool: ngen. exe 19 The Framework Class Library 22 The Common Type System The Common Language Specification Interoperability with Unmanaged Code 30 Chapter 2 Building, Packaging, Deploying, and Administering Applications and Types 33 NET Framework Deployment Goals 34 Building Types into a Module 35 Response Fil 36 A Brief Look at metadata 38 What do you think of this book We want to hear from you Microsoft is interested in hearing your feedback so we can continually improve our books and learning resources for you. To participate in a brief online survey, please visit microsoft. com/learning/booksurvey Combining Modules to Form an Assembly 45 Adding Assemblies to a Project by Using the Visual Studio IDE.51 Using the assembly Linker Adding Resource Files to an Assembly 53 Assembly Version Resource Information .54 Version numbers ..58 Culture Simple Application Deployment(Privately deployed Assemblies)...60 Simple Administrative Control(Configuration) 62 Chapter 3 Shared Assemblies and Strongly Named Assemblies 65 Two Kinds of Assemblies, Two Kinds of Deployment 66 Giving an Assembly a Strong Name 67 The global Assembly Cache 72 Building an Assembly That References a Strongly Named Assembly..74 Strongly named assemblies are tamper-Resistant 75 Delayed Signing Privately Deploying Strongly Named Assemblies How the Runtime Resolves Type References 80 Advanced Administrative Control( Configuration) 83 Publisher Policy control 86 PART I DESIGNING TYPES Chapter 4 Type Fundamentals 91 All Types Are Derived from System Object .91 Casting Between Types 93 Casting with the C# is and as Operators Namespaces and assemblies 97 How Things relate at Run time .101 Chapter 5 Primitive, Reference, and Value Types 111 Programming Language Primitive Types 111 Checked and Unchecked Primitive Type Operations 115 Reference Types and value Types 118 Boxing and Unboxing Value Types 124 Changing Fields in a Boxed Value Type by Using Interfaces and Why You Shouldnt Do This) 136 Object Equality and Identity 139 Object hash Codes .142 The dynamic Primitive Type ......144 Chapter 6 Type and member Basics 151 The Different Kinds of Type Members .151 Type visibilit 154 Friend assemblies 154 Member accessibility .156 Static Classes ...158 Partial Classes, Structures, and Interfaces .159 Components, Polymorphism, and Versioning 160 How the CLR Calls Virtual Methods, Properties, and Events 162 Using Type Visibility and Member Accessibility Intelligently...166 Dealing with Virtual Methods When Versioning Types 16 Chapter 7 Constants and Fields 175 Constants 175 Fⅰe|ds ...177 Chapter 8 Methods 181 Instance Constructors and Classes(Reference Types) 181 Instance Constructors and Structures(Value Types) 184 Type Constructors 187 Contents x Operator Overload Methods 191 Operators and Programming Language Interoperability 193 Conversion Operator Methods 195 Extension method 198 Rules and guidelines ....,200 Extending Various Types with Extension Methods 201 The Extension Attribute 203 Partial Methods 204 Rules and guidelines 207 Chapter 9 Parameters 209 Optional and Named Parameters 209 Rules and guidelines 210 The defaultParameter value and optional Attributes 212 Implicitly Typed Local Variabl 212 Passing parameters by reference to a Method 214 Passing a variable Number of arguments to a Method 220 Parameter and Return Type Guidelines 223 Const-nes 224 Chapter 10 Properties 227 Parameterless Properties 227 Automatically Implemented Properties 231 Defining Properties Intelligently 232 Object and collection Initializers 235 Anonymous Type .237 The System. Tuple type 240 Parameterful Properties 242 The performance of calling property accessor Methods 247 Property Accessor Accessibility 248 Generic prop A roperty Access 248