C#程序设计简介 英文技术资料翻译中文

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

英文原文:
C# Program Design
C# introduction
C# (pronounced “See Sharp”) is a simple, modern, object-oriented, and type-safe programming language. C# has its roots in the C family of languages and will be immediately familiar to C, C++, and Java programmers. C# is standardized by ECMA International as the ECMA-334 standard and by ISO/IEC as the ISO/IEC 23270 standard. Microsoft’s C# compiler for the .NET Framework is a conforming implementation of both of these standards.
C# is an object-oriented language, but C# further includes support for component-oriented programming. Contemporary software design increasingly relies on software components in the form of self-contained and self-describing packages of functionality. Key to such components is that they present a programming model with properties, methods, and events; they have attributes that provide declarative information about the component; and they incorporate their own documentation. C# provides language constructs to directly support these concepts, making C# a very natural language in which to create and use software components.
Several C# features aid in the construction of robust and durable applications: Garbage collection automatically reclaims memory occupied by unused objects; exception handling provides a structured and extensible approach to error detection and recovery; and the type-safe design of the language makes it impossible to read from uninitialized variables, to index arrays beyond their bounds, or to perform unchecked type casts.
C# has a unified type system. All C# types, including primitive types such as int and double, inherit from a single root object type. Thus, all types share a set of common operations, and values of any type can be stored, transported, and operated upon in a consistent manner. Furthermore, C# supports both user-defined reference types and value types, allowing dynamic allocation of objects as well as in-line storage of lightweight structures.
To ensure that C# programs and libraries can evolve over time in a compatible manner, much emphasis has been placed on versioning in C#’s design. Many programming languages pay little attention to this issue, and, as a result, programs written in those languages break more often than necessary when newer versions of dependent libraries are introduced. Aspects of C#’s design that were directly influenced by versioning considerations include the separate virtual and override modifiers, the rules for method overload resolution, and support for explicit interface member declarations.
Program structure
The key organizational concepts in C# are programs, namespaces, types, members, and assemblies. C# programs consist of one or more source files. Programs declare types, which contain members and can be organized into namespaces. Classes and interfaces are examples of types. Fields, methods, properties, and events are examples of members. When C# programs are compiled, they are physically packaged into assemblies. Assemblies typically have the file extension .exe or .dll, depending on whether they implement applications or libraries.
Types and variables
There are two kinds of types in C#: value types and reference types. Variables of value types directly contain their data whereas variables of reference types store references to their data, the latter being known as objects. With reference types, it is possible for two variables to reference the same object and thus possible for operations on one variable to affect the object referenced by the other variable. With value types, the variables each have their own copy of the data, and it is not possible for operations on one to affect the other (except in the case of ref and out parameter variables).
C#’s value types are further divided into simple types, enum types, struct types, and nullabl e types, and C#’s reference types are further divided into class types, interface types, array types, and delegate types.
Classes and objects
Classes are the most fundamental of C#’s types. A class is a data structure that combines state (fields) and actions (methods and other function members) in a single unit.
A class provides a definition for dynamically created instances of the class, also known as objects. Classes support inheritance and polymorphism, mechanisms whereby derived classes can extend and specialize base classes.
New classes are created using class declarations. A class declaration starts with a header that specifies the attributes and modifiers of the class, the name of the class, the base class (if given), and the interfaces implemented by the class. The header is followed by the class body, which consists of a list of member declarations written between the delimiters { and }.
Structs
Like classes, structs are data structures that can contain data members and function members, but unlike classes, structs are value types and do not require heap allocation. A variable of a struct type directly stores the data of the struct, whereas a variable of a class type stores a reference to a dynamically allocated object. Struct types do not support user-specified inheritance, and all struct types implicitly inherit from type object.
Structs are particularly useful for small data structures that have value semantics. Complex numbers, points in a coordinate system, or key-value pairs in a dictionary are all good examples of structs. The use of structs rather than classes for small data structures can make a large difference in the number of memory allocations an application performs.
Arrays
An array is a data structure that contains a number of variables that are accessed through computed indices. The variables contained in an array, also called the elements of the array, are all of the same type, and this type is called the element type of the array.
Array types are reference types, and the declaration of an array variable simply sets aside space for a reference to an array instance. Actual array instances are created dynamically at run-time using the new operator. The new operation specifies the length of the new array instance, which is then fixed for the lifetime of the instance. The indices of the elements of an array range from 0 to Length - 1. The new operator automatically initializes the elements of an array to their default value, which, for example, is zero for all numeric types and null for all reference types.
Interfaces
An interface defines a contract that can be implemented by classes and structs. An interface can contain methods, properties, events, and indexers. An interface does not provide implementations of the members it defines—it merely specifies the members that must be supplied by classes or structs that implement the interface.Interfaces may employ multiple inheritance.
Lexical structure
Programs
A C# program consists of one or more source files, known formally as compilation units (§9.1). A source file is an ordered sequence of Unicode characters. Source files typically have a one-to-one correspondence with files in a file system, but this correspondence is not required. For maximal portability, it is recommended that files in a file system be encoded with the UTF-8 encoding.
Conceptually speaking, a program is compiled using three steps:
1. Transformation, which converts a file from a particular character repertoire and encoding scheme into a sequence of Unicode characters.
2. Lexical analysis, which translates a stream of Unicode input characters into a stream of tokens.
3. Syntactic analysis, which translates the stream of tokens into executable code.
Grammars
This specification presents the syntax of the C# programming language using two grammars. The lexical grammar (§2.2.2) defines how Unicode characters are combined to form line terminators, white space, comments, tokens, and pre-processing directives. The syntactic grammar (§2.2.3) defines how the tokens resulting from the lexical grammar are combined to form C# programs.
Grammar notation
The lexical and syntactic grammars are presented using grammar productions. Each grammar production defines a non-terminal symbol and the possible expansions of that
non-terminal symbol into sequences of non-terminal or terminal symbols. In grammar productions, non-terminal symbols are shown in italic type, and terminal symbols are shown in a fixed-width font.
The first line of a grammar production is the name of the non-terminal symbol being defined, followed by a colon. Each successive indented line contains a possible expansion of the non-terminal given as a sequence of non-terminal or terminal symbols.
conclusion
Therefore, c # is a kind of modern, type safety, object-oriented programming language, it enables programmers to quickly and easily for Microsoft. NET platform to develop solutions.
中文译文:
C#程序设计简介
C#介绍
C#(发音为“See Sharp”)是一个简单的、现代的、面向对象的编程语言类型。

C#起源于C语言并类似于C、c++和Java语言。

C#是标准化的ECMA国际作为ECMA - 334标准和ISO / IEC作为ISO / IEC 23270标准。

微软的C#编译器和净框架是一个符合标准的实现。

C#是一种面向对象语言,但C#进一步包括支持面向组件编程。

现代软件设计越来越依赖软件组件在形式的独立和自我描述包的功能。

关键是,他们现在这样的组件编程模型与属性、方法和事件;他们有属性,提供声明性信息的组件;他们有他们自己的文档。

C#提供了语言结构直接支持这些概念,使C#非常自然语言来创建和使用的软件组件。

几个C#特性援助建设的强劲和持久的应用:垃圾收集自动回收内存占用未使用的对象;异常处理提供了一个结构化的和可扩展的方式错误检测和恢复,和类型安全的设计语言使它无法读取变量未初始化,数组索引超出了他们的范围,或执行未经检查的类型。

C#有一个统一的类型系统。

所有的C#类型,包括原语类型,例如int和double,继承自一个根对象类型。

因此,所有类型共享一组常见的操作,和任何类型的值可以存储、运输和操作在一个一致的方式。

此外,C#既支持用户定义的引用类型和值类型,允许动态分配的对象以及在线存储轻质结构。

确保c#程序和库可以随时间演化的一个兼容的方式,多版本管理的重点是在C#的设计。

许多编程语言几乎没有注意到这个问题,因此,这些语言编写的程序在打破新版本的时候介绍了它。

方便的C#的设计,直接影响到版本控制因素包括单独的虚拟和覆盖修饰符,方法重载解析规则,支持显式接口成员声明。

程序结构
组织概念的关键在C#项目,命名空间、类型、成员和总成。

C#程序包含一个或多个源文件。

项目申报类型,它包含的成员,可以组织成名称空间。

类和接口是类型的例子。

字段、方法、属性和事件成员的例子。

当C#程序编译,他们亲自打包。

组件通常有文件扩展名.exe或.sdll,这取决于他们是否实现应用程序或库。

类型和变量
有两种类型在C#中:值类型和引用类型。

值类型的变量直接包含他们的数据,而引用类型的变量存储引用他们的数据,后者被称为对象。

与引用类型,因此可能出现两个变量来引用同一个对象,从而可能影响到一个变量操作的对象引用的其他变量。

与值类型一样,每变量个都有自己拷贝的数据,而且我们不可能操作在一个影响其他(除对于ref的参数变量)。

C#的值类型进一步划分为简单类型、枚举类型、结构类型和可空类型和C#的引用类型进一步划分为类类型,接口类型,数组类型,并委托类型。

类和对象
类是最基本的C#的类型。

一个类是一个数据结构,结合状态(字段)和行为(方法和其他函数成员)在一个单一的单位。

定义一个类提供了一个动态创建类的实例,也称为对象。

类支持继承和多态性,通过派生类可以扩展和专业基础课程。

创建新类是使用类声明。

一个类声明始于一个头,指定属性和修饰符的类,类名,基类(if given),以及实施的接口类。

标题是紧随其后的是类体,它包括一组的成员声明写之间的分隔符{and}。

结构
像类一样,结构是数据结构可以包含数据成员和函数成员,但与类不同的是,结构是值类型,不需要堆分配。

一个结构体类型变量可以是直接存储数据的结构,而一个变量的一个类的类型的引用必须存储到一个动态分配的对象中。

结构体类型不支持指定的继承,和所有类型的结构体类型对象隐式继承。

结构尤其适用于小型数据结构,有价值的语义。

复杂的数字,分在一个坐标系,或键-值对的字典都是很好的例子的结构体。

使用结构体而不是类为小型数据结构可以使一个大的差异数量的内存分配一个应用程序执行。

数组
数组是一种数据结构,其中包含大量的变量,并通过计算指标。

包含在一个数组的变量,也称为数组的元素,都是相同的类型,这种类型称为数组的元素类型。

数组类型是引用类型,数组变量的声明只是预留空间为一个引用一个数组实例。

实际数组实例在运行时动态地创建使用新的操作符。

新的操作指定长度的新数组实例,然后固定为一生的实例。

索引数组中的元素的范围从0到长度- 1。

新算子自动初始化一个数组的元素为它们的默认值,例如,对于所有的数值类型是零和null对于所有引用类型。

接口
一个接口定义了一个连接,可以实现类和结构体。

一个接口可以包含方法、属性、事件和索引器。

一个接口不提供实现成员,只定义了它指定的成员,且必须提供类或结构,实现接口。

接口可以使用多重继承。

词法结构
项目
一个C#程序由一个或多个源文件,正式称为编译单元。

源文件是一个有序
的Unicode字符序列。

源文件通常有一个一对一的对应文件的文件系统,但这些不是必需的。

最大的可移植性,建议文件在文件系统中被编码和utf - 8编码。

从概念上讲,一个程序被编译使用三个步骤:
1.变换,它将一个文件从一个特定的字符集和编码方案变为一系列的Unicode字符。

2.词法分析,这意味着一连串的Unicode字符输入流的令牌。

3.句法分析,转化为可执行的代码标记流。

语法
本书规范地提出了语法的C#编程语言使用两种语法。

词法语法定义了Unicode字符组合起来形成线终端、空格、注释、令牌和预处理指令。

句法语法定义了如何把产生的词汇语法组合起来形成C#项目。

语法符号
在词法和句法语法是使用语法作品呈现。

每个语法定义了一个非终结符符号和可能的扩展的非终结符符号到序列的非终结符或终端符号。

在语法中,非终结符符号显示在斜体,终端符号显示在一个固定宽度字体。

第一行的语法用非终结符符号的名称定义,后跟一个冒号。

每个连续的线包含一个可能扩张的非终结符作为一个序列的非终结符或终端符号。

结束语
因此,C#是一种现代的,类型安全的,面向对象的编程语言,它使得程序员能够快速而容易的为微软.NET平台开发解决方案。

相关文档
最新文档