译文: C#基础介绍 出自 本科毕业设计(论文)外文翻译 作符和潜逃类型。 一个声明在声明所属的声明域定义了一个名称。除了重载构造函数,方法,索引和操作符名称,在一个声明域种有两个或更多介绍有相同名称成员的声明时,是错误的。对一个而生命域中,包含有相同名称的不同种类成员是永远不可能的。例如,一个声明域种不能包括有相同名称的域和方法。这里有许多种不同类型的声明域,如下表示: 在所有程序的源文件种,不包括嵌套名称空间声明的名称空间成员声明都是一个单独的组合声明域,称为全局声明域。 在所有程序的源文件种,名称空间成员声明和有相同完整正确的名称空间名称的名称空间声明都是一个单独的组合声明域。 每个类,结构或接口声明都会创建一个新的声明域。名称通过类成员声明,结构成员什么或接口成员声明介绍到这个声明域中。除了重载构造函数声明和静态构造函数声明,一个类类或结构成员声明不能引入域类或结构名称相同的成员。一个类,节后或接口允许方法和所以的重载。此外,一个类声明的方法,而在他们各自签名中提供了不同的方法声明。注意基类不影响类的声明域。而基本接口不影响一个接口的声明域。这样,一个派生的类或接口可以用和继承的成员相同的名称声明一个成员。这样的一个成员贝成为隐藏了继承的成员。 每个枚举声明创建一个新的声明域。名称通过枚举成员声明介绍到声明域中。 每个块或者转换为局部变量创建一个分立声明域。名称通过局部变量声明贝引入到这个声明域。如果一个块是构造函数或方法声明的主体,在形参列表中声明的参数是这2个块的局部变量声明域的成员。块的局部变量声明域包括任何嵌套块。因而,在一个嵌套块中不太可能用域嵌套块中的局部变量有相同名称声明一个局部变量 每个块或转换块为标签创建一个分立的声明域。名称通过标签声明贝引入到这个声明域,而名称通过GOTO声明引入到这2个声明域。块的局部变量声明域包括任何嵌套块。因而,在一个嵌套块中不太可能用域嵌套块中的标签想同名称声明一个标签。 在名称贝声明的文本顺序通常并不重要。特别是,文本顺序对于声明和使用名称空间,类型,常数,方法,属性,时间,索引,操作符,构造函数,析构函数和静态构造函数来说并不重要。声明顺序在下面的途径才是重要的: ·域声明和局部变量的声明顺序决定了他们的初始化是按声明顺序执行。 ·局部变量必须在他们被使用前定义。 ·当常数表达式数值贝忽略,枚举成员的声明顺序是重要的。 C#语言的类型被分为三类:数值类型,引用类型和指针类型。 2 本科毕业设计(论文)外文翻译 TYPE: VALUE-TYPE REFERENCE-TYPE POINTER-TYPE 指针类型只能用在不安全代码。 数值类型与引用类型所不同的是,数值类型变量直接含有他们的数据,然而引用类型的变量存储对他们的数据的引用,就是后面要接受的对象。独语引用类型,可能会出现两个变量引用相同对象的情况,这样对于一个变量的操作就有可能影响到由其他变量引用的对象。对于数值类型,每个变量都有他们自己对数据的拷贝,这样就不能能出现一个对变量的操作影响到另外一个的情况。 C#的类型系统是统一的,这样任何类型的数据都可以贝看作对象。C#中的任何类型都直接或简介地从BOJIECT类类型派生,而OBJECT是所有类型的最基本类。引用类型的数值贝看作通过对象,这些对象通过把数值看作类型对象来简化。数值类型的数值通过包装和解包装操作来贝当作对象。 变量代表数据的实际存储位置。每各变量所能存储的数值由它本省的类型决定。C++语言是一种类项安全语言(TSL),而且C++编译器保证每一个数值贝保存在相应的变量中。变量的数值可以通过赋值或者++或-运算符改变。 在变量贝赋值以前,变量自身的类型必须贝明确的声明。 变量或者贝初始化的或者未初始化的。一个初始化的变量在贝定义时贝赋予了一个确定的初始值,而未初始化的变量在定义时并未贝赋予确定的初始值。对于一个在程序某处贝认为具有确定数值的IUA,必然在指向这一位置的所有可能的执行路径上存在赋值操作。 C#语言的大多数都使得程序员可以制定关于在程序中定义的实体的公开的消息。例如,一个类中的一个方法的可访问性,可以通过用方法修饰符PUBLIC,PROTECTED,INTERNAL和PRIVATE对它进行修饰来制定。 C#使得程序员可以创造声明信息的新的种类,来为各种程序实体指定声明信息,并且在运行时环境中找回属性信息。例如,一个框架也许定义了一个HELPATTRIBUTE属性,它可以被放在例如类和方法的程序元素种类来提供从程序元素到他们的文档的映射。 声明信息的新种类通过属性类的声明来定义,它可能有位置的和名称的参数。声明信息使用属性来指定C#程序,并且可以在运行是作为属性实例来检索。 3 本科毕业设计(论文)外文翻译 原文: C# basic introduction From 本科毕业设计(论文)外文翻译 for overloaded constructor, method, indexer, and operator names, it is an error to have two or more declarations that introduce members with the same name in a declaration space. It is never possible for a declaration space to contain different kinds of members with the same name. For example, a declaration space can never contain a field and a method by the same name. There are several different types of declaration spaces, as described in the following. Within all source files of a program, namespace-member-declarations with no enclosing namespace-declaration are members of a single combined declaration space called the global declaration space. Within all source files of a program, namespace-member-declarations within namespace-declarations that have the same fully qualified namespace name are members of a single combined declaration space. Each class, struct, or interface declaration creates a new declaration space. Names are introduced into this declaration space through class-member-declarations, struct-member-declarations, or interface-member-declarations. Except for overloaded constructor declarations and static constructor declarations, a class or struct member declaration cannot introduce a member by the same name as the class or struct. A class, struct, or interface permits the declaration of overloaded methods and indexers. A class or struct furthermore permits the declaration of overloaded constructors and operators. For instance, a class, struct, or interface may contain multiple method declarations with the same name, provided these method declarations differ in their signature. Note that base classes do not contribute to the declaration space of a class, and base interfaces do not contribute to the declaration space of an interface. Thus, a derived class or interface is allowed to declare a member with the same name as an inherited member. Such a member is said to hide the inherited member. Each enumeration declaration creates a new declaration space. Names are introduced into this declaration space through enum-member-declarations. Each block or switch-block creates a separate declaration space for local variables. Names are introduced into this declaration space through local-variable-declarations. If a block is the body of a constructor or method declaration, the parameters declared in the formal-parameter-list are members of the block’s local variable declaration space. The local variable declaration space of a block includes any nested blocks. Thus, within a nested block it is not possible to declare a local variable with the same name as a local variable in an enclosing block. Each block or switch-block creates a separate declaration space for labels. Names are introduced into this declaration space through labeled-statements, and the names are referenced through goto-statements. The label declaration space of a block includes any nested blocks. Thus, within a nested block it is not possible to declare a label with the same name as a label in an enclosing block. The textual order in which names are declared is generally of no significance. In particular, textual order is not significant for the declaration and use of namespaces, types, constants, methods, properties, events, indexers, operators, constructors, destructors, and static constructors. Declaration order is significant in the following ways: Declaration order for field declarations and local variable declarations determines the order in which their initializers (if any) are executed. Local variables must be defined before they are used. Declaration order for enum member declarations is significant when constant-expression values are omitted. The types of the C# language are divided into three categories: Value types, reference types, and 5 本科毕业设计(论文)外文翻译 pointer types. type: ➢ value-type ➢ reference-type ➢ pointer-type Pointer types can be used only in unsafe code. Value types differ from reference types in that variables of the value types directly contain their data, whereas variables of the reference types store references to their data, the latter 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. C#’s type system is unified such that a value of any type can be treated as an object. Every type in C# directly or indirectly derives from the object class type, and object is the ultimate base class of all types. Values of reference types are treated as objects simply by viewing the values as type object. Values of value types are treated as objects by performing boxing and unboxing operations . Variables represent storage locations. Every variable has a type that determines what values can be stored in the variable. C# is a type-safe language, and the C# compiler guarantees that values stored in variables are always of the appropriate type. The value of a variable can be changed through assignment or through use of the ++ and -- operators. A variable must be definitely assigned before its value can be obtained. As described in the following sections, variables are either initially assigned or initially unassigned. An initially assigned variable has a well defined initial value and is always considered definitely assigned. An initially unassigned variable has no initial value. For an initially unassigned variable to be considered definitely assigned at a certain location, an assignment to the variable must occur in every possible execution path leading to that location. Much of the C# language enables the programmer to specify declarative information about the entities defined in the program. For example, the accessibility of a method in a class is specified by decorating it with the method-modifiers public, protected, internal, and private. C# enables programmers to invent new kinds of declarative information, to specify declarative information for various program entities, and to retrieve attribute information in a run-time environment. For instance, a framework might define a HelpAttribute attribute that can be placed on program elements such as classes and methods to provide a mapping from program elements to documentation for them. New kinds of declarative information are defined through the declaration of attribute classes, which may have positional and named parameters. Declarative information is specified a C# program using attributes, and can be retrieved at run-time as attribute instances. 6 因篇幅问题不能全部显示,请点此查看更多更全内容