版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認(rèn)領(lǐng)
文檔簡介
1、本科畢業(yè)設(shè)計(論文外文翻譯譯文:C#基礎(chǔ)介紹出自作者Anders Hejlsberg and Scott WiltamuthC#是一種簡單,現(xiàn)代,面向?qū)ο蠛皖愋桶踩木幊陶Z言,由C和C+發(fā)展而來。C#牢固地植根于C和C+語言族譜種,并且會很快被C和C+程序員所熟悉。C#的目標(biāo)在于把VISUAL BASIC的高生產(chǎn)力和C+本身的能力結(jié)合起來。C#作為MICROSOFT Visual Studio 7.0的一部分提供給用戶。除了C#以外,Visual Studio還支持Visual Basic,Visual+和描述語言Vbscript和Jscript.所有這些語言都提供對Microsoft.NET
2、 平臺的訪問能力,它包括一個通用的執(zhí)行引擎和一個豐富的類庫。Microsoft.NET平臺定義了一個“通用語言子集”(CLS),是一種混合語言,它可以增強CLS兼容語言和類庫間的無縫協(xié)同工作能力。對于C#開發(fā)者,這意味著既是C#是一種新的語言,它已經(jīng)可以對用老牌工具如Visual Basic和Visual C+使用的豐富類庫進行完全訪問。C#子集并沒有包含一個類庫。一個C#程序由一個或多個源文件組成。一個源文件是一個統(tǒng)一字符編碼的字符的有序序列。燕文件通常和文件系統(tǒng)種的文件有一一對應(yīng)關(guān)系,但是這個對應(yīng)關(guān)系并不需要。從概念來講,一個程序在編譯時有四步:1. 預(yù)處理,一種文本到文本的轉(zhuǎn)換,這使得可
3、以對程度需文本進行條件飽和和刪除。2. 語法分析,它把輸入字符序列轉(zhuǎn)換為一個標(biāo)記序列。3. 句法分析,它把標(biāo)記序列轉(zhuǎn)換為可執(zhí)行代碼。C#的詞匯和句子的文法散步在整個文章中。詞匯文法定義如能把字符組合為形式標(biāo)記:句子的文法定義了如何把標(biāo)記組合為C#程序。文法生成包括無詞尾符號和有詞尾符號。在文法生成當(dāng)中,無詞尾符號用意大利體表示,而有詞尾符號用定寬字體。每一個吳詞尾符號定義為一系列產(chǎn)品(PRODUCTION)。這一系列產(chǎn)品的第一行是吳詞尾符號的名稱,接下來是一個冒號。對于一個場頻,每個連續(xù)的鋸齒狀的行的右手邊同左手邊類似是無詞尾符號。C#程序中的生命定義了程序的重要聲明。C#程序用名稱空間來組織
4、,它可以包含類型聲明和潛逃聲明。類型聲明用來定義類,結(jié)構(gòu),接口,類的聲明可以包含實例構(gòu)造函數(shù),析構(gòu)函數(shù),靜態(tài)構(gòu)造函數(shù),常數(shù),域,方法,屬性,時間,索引,操作符和潛逃類型。一個聲明在聲明所屬的聲明域定義了一個名稱。除了重載構(gòu)造函數(shù),方法,索引和操作符名稱,在一個聲明域種有兩個或更多介紹有相同名稱成員的聲明時,是錯誤的。對一個而生命域中,包含有相同名稱的不同種類成員是永遠(yuǎn)不可能的。例如,一個聲明域種不能包括有相同名稱的域和方法。這里有許多種不同類型的聲明域,如下表示:在所有程序的源文件種,不包括嵌套名稱空間聲明的名稱空間成員聲明都是一個單獨的組合聲明域,稱為全局聲明域。在所有程序的源文件種,名稱空
5、間成員聲明和有相同完整正確的名稱空間名稱的名稱空間聲明都是一個單獨的組合聲明域。每個類,結(jié)構(gòu)或接口聲明都會創(chuàng)建一個新的聲明域。名稱通過類成員聲明,結(jié)構(gòu)成員什么或接口成員聲明介紹到這個聲明域中。除了重載構(gòu)造函數(shù)聲明和靜態(tài)構(gòu)造函數(shù)聲明,一個類類或結(jié)構(gòu)成員聲明不能引入域類或結(jié)構(gòu)名稱相同的成員。一個類,節(jié)后或接口允許方法和所以的重載。此外,一個類聲明的方法,而在他們各自簽名中提供了不同的方法聲明。注意基類不影響類的聲明域。而基本接口不影響一個接口的聲明域。這樣,一個派生的類或接口可以用和繼承的成員相同的名稱聲明一個成員。這樣的一個成員貝成為隱藏了繼承的成員。每個枚舉聲明創(chuàng)建一個新的聲明域。名稱通過枚舉
6、成員聲明介紹到聲明域中。每個塊或者轉(zhuǎn)換為局部變量創(chuàng)建一個分立聲明域。名稱通過局部變量聲明貝引入到這個聲明域。如果一個塊是構(gòu)造函數(shù)或方法聲明的主體,在形參列表中聲明的參數(shù)是這2個塊的局部變量聲明域的成員。塊的局部變量聲明域包括任何嵌套塊。因而,在一個嵌套塊中不太可能用域嵌套塊中的局部變量有相同名稱聲明一個局部變量每個塊或轉(zhuǎn)換塊為標(biāo)簽創(chuàng)建一個分立的聲明域。名稱通過標(biāo)簽聲明貝引入到這個聲明域,而名稱通過GOTO聲明引入到這2個聲明域。塊的局部變量聲明域包括任何嵌套塊。因而,在一個嵌套塊中不太可能用域嵌套塊中的標(biāo)簽想同名稱聲明一個標(biāo)簽。在名稱貝聲明的文本順序通常并不重要。特別是,文本順序?qū)τ诼暶骱褪褂?/p>
7、名稱空間,類型,常數(shù),方法,屬性,時間,索引,操作符,構(gòu)造函數(shù),析構(gòu)函數(shù)和靜態(tài)構(gòu)造函數(shù)來說并不重要。聲明順序在下面的途徑才是重要的:域聲明和局部變量的聲明順序決定了他們的初始化是按聲明順序執(zhí)行。局部變量必須在他們被使用前定義。當(dāng)常數(shù)表達式數(shù)值貝忽略,枚舉成員的聲明順序是重要的。C#語言的類型被分為三類:數(shù)值類型,引用類型和指針類型。TYPE:VALUE-TYPEREFERENCE-TYPEPOINTER-TYPE指針類型只能用在不安全代碼。數(shù)值類型與引用類型所不同的是,數(shù)值類型變量直接含有他們的數(shù)據(jù),然而引用類型的變量存儲對他們的數(shù)據(jù)的引用,就是后面要接受的對象。獨語引用類型,可能會出現(xiàn)兩個變
8、量引用相同對象的情況,這樣對于一個變量的操作就有可能影響到由其他變量引用的對象。對于數(shù)值類型,每個變量都有他們自己對數(shù)據(jù)的拷貝,這樣就不能能出現(xiàn)一個對變量的操作影響到另外一個的情況。C#的類型系統(tǒng)是統(tǒng)一的,這樣任何類型的數(shù)據(jù)都可以貝看作對象。C#中的任何類型都直接或簡介地從BOJIECT類類型派生,而OBJECT是所有類型的最基本類。引用類型的數(shù)值貝看作通過對象,這些對象通過把數(shù)值看作類型對象來簡化。數(shù)值類型的數(shù)值通過包裝和解包裝操作來貝當(dāng)作對象。變量代表數(shù)據(jù)的實際存儲位置。每各變量所能存儲的數(shù)值由它本省的類型決定。C+語言是一種類項安全語言(TSL),而且C+編譯器保證每一個數(shù)值貝保存在相應(yīng)
9、的變量中。變量的數(shù)值可以通過賦值或者+或-運算符改變。在變量貝賦值以前,變量自身的類型必須貝明確的聲明。變量或者貝初始化的或者未初始化的。一個初始化的變量在貝定義時貝賦予了一個確定的初始值,而未初始化的變量在定義時并未貝賦予確定的初始值。對于一個在程序某處貝認(rèn)為具有確定數(shù)值的IUA,必然在指向這一位置的所有可能的執(zhí)行路徑上存在賦值操作。C#語言的大多數(shù)都使得程序員可以制定關(guān)于在程序中定義的實體的公開的消息。例如,一個類中的一個方法的可訪問性,可以通過用方法修飾符PUBLIC,PROTECTED,INTERNAL和PRIVATE對它進行修飾來制定。C#使得程序員可以創(chuàng)造聲明信息的新的種類,來為各
10、種程序?qū)嶓w指定聲明信息,并且在運行時環(huán)境中找回屬性信息。例如,一個框架也許定義了一個HELPATTRIBUTE屬性,它可以被放在例如類和方法的程序元素種類來提供從程序元素到他們的文檔的映射。聲明信息的新種類通過屬性類的聲明來定義,它可能有位置的和名稱的參數(shù)。聲明信息使用屬性來指定C#程序,并且可以在運行是作為屬性實例來檢索。原文:C# basic introductionFrom written by Anders Hejlsberg and Scott WiltamuthC# is a simple, modern, object oriented, and type-safe progra
11、mming language derived from C and C+. C# (pronounced “C sharp” is firmly planted in the C and C+ family tree of languages, and will immediately be familiar to C and C+ programmers. C# aims to combine the high productivity of Visual Basic and the raw power of C+.Here I will introduce some important s
12、erise numbers to explain the C#.C# is provided as a part of Microsoft Visual Studio 7.0. In addition to C#, Visual Studio supports Visual Basic, Visual C+, and the scripting languages VBScript and JScript. All of these languages provide access to the Next Generation Windows Services (NWGS platform,
13、which includes a common execution engine and a rich class library. The .NET software development kit defines a Common Language Subset (CLS, a sort of lingua franca that ensures seamless interoperability between CLS-compliant languages and class libraries. For C# developers, this means that even thou
14、gh C# is a new language, it has complete access to the same rich class libraries that are used by seasoned tools such as Visual Basic and Visual C+. C# itself does not include a class library.A C# program consists of one or more source files. A source file is an ordered sequence of Unicode character
15、s. Source files typically have a one-to-one correspondence with files in a file system, but this correspondence is not required by C#.Conceptually speaking, a program is compiled using four steps:Pre-processing, a text-to-text translation that enables conditional inclusion and exclusion of program t
16、ext.Lexical analysis, which translates a stream of input characters into a stream of tokens. Syntactic analysis, which translates the stream of tokens into executable code.Lexical and syntactic grammars for C# are interspersed throughout this specification. The lexical grammar defines how characters
17、 can be combined to form tokens; the syntactic grammar defines how tokens can be combined to form C# programs.Grammar productions include non-terminal symbols and terminal symbols. In grammar productions, non-terminal symbols are shown in italic type, and terminal symbols are shown in a fixed-width
18、font. Each non-terminal is defined by a set of productions. The first line of a set of productions is the name of the non-terminal, followed by a colon. Each successive indented line contains the right-hand side for a production that has the non-terminal symbol as the left-hand side.Declarations in
19、a C# program define the constituent elements of the program. C# programs are organized using namespaces, which can contain type declarations and nested namespace declarations. Type declarations are used to define classes, structs, interfaces, enums, and delegates. The kinds of members permitted in a
20、 type declaration depends on the form of the type declaration. For instance, class declarations can contain declarations for instance constructors, destructors, static constructors, constants, fields, methods, properties, events, indexers, operators, and nested types.A declaration defines a name in
21、the declaration space to which the declaration belongs. Except 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 di
22、fferent 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 enc
23、losing 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 dec
24、laration 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 con
25、structor 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 an
26、d 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 t
27、he 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 declarati
28、on 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
29、in the formal-parameter-list are members of the blocks 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
30、.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 blo
31、ck 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
32、, 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 mus
33、t 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 pointer types.type: value-type reference-type pointer-typePoin
34、ter 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 varia
35、bles 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
36、 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 ty
37、pes 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 o
38、f 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
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 紙袋制作課件教學(xué)課件
- 防蜇課件教學(xué)課件
- 獲獎 課件教學(xué)課件
- 2024年度農(nóng)產(chǎn)品收購合同
- 2024年企業(yè)安全評價與咨詢服務(wù)合同
- 2024年度空氣能設(shè)備安裝與驗收合同
- 2024國際快遞服務(wù)全面合作協(xié)議
- 2024樁基工程施工合同范本樁基工程施工合同
- 2024年企業(yè)合并收購協(xié)議
- 2024個人租房的合同模板范本
- GB 30255-2019室內(nèi)照明用LED產(chǎn)品能效限定值及能效等級
- 全套教學(xué)課件《管理學(xué)基礎(chǔ)》
- 深度解讀強基計劃-被強基計劃課件
- 第五章肺孢子菌病課件
- 魏晉南北朝服飾課件
- 無機及分析化學(xué)考試題(附答案)
- 可可脂巧克力課件
- 交通連四方 杭州交通的發(fā)展課件
- 梨樹栽培技術(shù) 課件
- 第13講 教學(xué)設(shè)計的ASSURE模式(V5.1)公開課一等獎省優(yōu)質(zhì)課大賽獲獎?wù)n件
- 三年級上冊美術(shù)課件-3.色彩的變化|贛美版 (共19張PPT)
評論
0/150
提交評論