版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、What Is the .NET Framework?The .NET Framework is a new and revolutionary platform created by develoapplications.forThe mosteresting thing about this sement is how vague Ive been but thereare good reasons for this. For a start, notet I didnt say develoapplications onthe Windows operating system. Alth
2、ough therelease of the .NETFramework runs on the Windows operating system, it is fastingsible tofind alternative verst will work on others. One exle of this is Mono, anopen source verof the .NET Framework (including a C# compiler)t will runon several operating systems, including various flavors of L
3、inux and Mac OS. Moresuch projects arehpeline and may be availaby the time you read this. Inaddition, you can use theof the full .NET Framework) on.NET Compact Framework (essentially a subsetal digital assistant (PDA) class deviandeven some smartphones. One of the key motivational forbehind the .NET
4、Framework is itsended use as a means ofegrating disparate operating systems.In addition, the definition of the .NET Framework given above includes no restrictionon the type of applicationst aresible. This is because there is no restriction the .NET Framework allows the creation of Windows applicatio
5、ns, Web applications,Web servi, and pretty much anything else you can think of.the .NET Framework has been designed sot it can be used from any language.This includes the subject of this book, C#, as well as C+, Visual Basic, JScript, andeven older languagech as COBOL. For this to work, .NET-specifi
6、c vers ofthese languages have also appeared, and more are being released all the time. Notonly do all of these have acs to the .NET Framework, but they csocommunicate with each other. It is perfectlysible for C# developers to make useof code written by Visual Basic programmers, and vice versa.All of
7、 this provides a hitherto unthinkable level of versatility and is part of whatmakes using the .NET Framework such an attractive prospect.Whatshe .NET Framework?the .NET Framework consists primarily of a giglibrary of codet you use fromyour cnt languages (such as C#) using object-oriented programming
8、 (OOP)techniques. This library is categorizedo different modules you use portions of itdepending on the results you want to achieve. For exle, one module contains thebuilding blocks for Windows applications, another for network programming, andanother for Web development. Some modules are dividedo m
9、ore specificsubmodules, such as a module for building Web servidevelopment.withhe module for WebTheention here is for different operating systems to support some or all of thesemodules, depending on their characteristics. A PDA, for exle, would includesupport for all the core .NET functionality, but
10、 is unlikely to require some of the moreesoteric modules.Part of the .NET Framework library defines some basic types. A type is arepresenion of data, and specifying some of the most fundamental of these (such asa 32-bit signedeger) facilieseroper- ability betn languages usingthe .NET Framework. This
11、 is called the the Common Type System (CTS).As well applying this library, the Framework also includes the .NET CommonLanguage Runtime (CLR), which is responsible for maapplications developed using the .NET library.aining the execution of allHowWrite Applications Using the .NET Framework?Writing an
12、application using the .NET Framework means writing code (using any ofthe languagest support the Framework) using the .NET cibrary.his bookyou use VS for your development VS is aerful,egrated developmentenvironmentt supports C# (as well as managed and unmanaged C+, Visual Basic,and some others). The
13、advantage of this environment is the ease with which .NETfeatures can beegratedo your code. The codet you will create will beentirely C# but will use the .NET Framework throughout, and you make use of theadditional tools in VS where nesary.In order for C# code to execute, it must be convertedo a lan
14、guaget theoperating system understands, known as native code. This converis calledcompiling code, an actt is performed by a compiler. Under the .NET Framework,however, this is a two-stage pros.MSIL and JITWhen you compile codet uses the .NET Framework library, you dontimmediay create operating syste
15、mspecific native code. Instead, you compile yourcodeoermediaanguage (MSIL) code. This code isnt specific toany operating system and isnt specific to C#. Other .NET languages for exle,Visual Basic .NET also compile to this language as astage. This compilationsts carried out by VS when you use it to d
16、evelop C# applications.Obviously, to execute an application more work is nesary. This is the job of aJust-ime (JIT) compiler, which compiles MSILo native codet is specific tothe OS and machine architecture beinged. Only at this pocan the OS executethe application. the just-ime part of the name here
17、reflects the factt MSIL codeis only compiled as and when it is needed.he past, it was often nesary to compile your codeo several applications, eachof whiched a specific operating system and Crchitecture. Often, this was aform of optimization (to get code to run faster on an AMD chipset, for exle), b
18、utat times it was critical (for applications to work in both Win9x and WinNT/2000environments, for exle). This is now unnesary, because JIT compilers (as theirname suggests) use MSIL code, which is independent of the machine, operatingsystem, and CPU. Several JIT compilers exist, eaching a different
19、 architecture,and the appropriateill be used to create the native code required.The beauty of all this ist it requires a lot less work on your part in fact, you canjust fet about system-dependent details and concentrate on the moreerestingfunctionality of your code.AssembsWhen you compile an applica
20、tion, the MSIL code created is stored in an assembly.Assembs include both executable application filest you can run directly fromWindows without the need for any othrograms (these have a .exe file exten),and libraries for use by other applications (which have a .dll exten).As well as containing MSIL
21、, assembs also contaeta information (t is,information about the information containedhe assembly, also known as metadata)and optional resour(additional data used by the MSIL, such as sound files andpictures). The meta information allows assembs to be fully self-descriptive. Youneed no other informat
22、ion to use an assembly, meaningt you avoid situationchas failing to add required dao the system registry and so on, which was often aproblem when develowith othlatforms.This meanst deploying applications is often as simple as copying the fileso adirectory on a remote computer. Since no additional in
23、formation is required on thesystems, you can just run an executable file from this directory and (athe .NET CLR is installed) away you go.mingOf course, you wont nesarily want to include everything required to run anapplication in one place. You might write some codet performs tasks required bymulti
24、ple applications. In situations like this, it is often useful to place this reusablecode in a place acsible to all applications.he .NET Framework, this is the thehis cache is simple you just placeGlobal Assembly Cache (GAC). Placing codethe assembly containing the codehe directory containing this ca
25、che.Managed CodeThe role of the CLR doesnt end once you have compiled your code to MSIL, and a JIT compiler has compiled this to native code. Code written using the .NETFramework is managed when it is executed (this stage is usually referred to as beingat runtime). This meanst the CLR looks after yo
26、ur applications by managingmemory, handling security, allowing cross-language debugging, and so on. Bycontrast, applicationst do not run under the control of the CLR are said to beunmanaged and certain languagech as C+ can be used to write such applicationst, for exle, acs low-level functions of the
27、 operating system. However, in C#you can write only codet runs in a managed environment. You will make use ofthe managed features of the CLR and allow .NET itself to handle anythe operating system.eraction withGarbage CollectionOne of the most important features of managed code is the concept of gar
28、bagecollection. This is the .NET method of making suret the memory used by anapplication is freed up compley when the application is no longer in use. Prior to .NET this has mostly been the responsibility of programmers, and a few simpleerrors in code could result in large blocks of memory mysteriou
29、sly disappearing as aresult of being allocated to the wrong placeemory. This usually meant aprogressive slowdown of your computer followed by a system crash.NET garbage collection works by inspecting the memory of your computer every sooften and removing anything from itt is no longer needed. There
30、is no settimeframe for this; it mighppen thousands of times a second, once every fewseconds, or whenever, but you can rest aredt it will happen.There are some implications for programmers here. Since this work is done for you atan unpredictable time applications have to be designed with thisind. Cod
31、etrequires a lot of memory to run should tidy itself up rathern waiting farbagecollection to happen, but this isnt anything like as tricky as it sounds.Fitting It TogetherBefore moving on, Ill summarize the steps required to create a .NET application asdiscussed previously:Application code is writte
32、n using ain Figure 1-1.patible language such as C#, as shownFigure 1-1This code is compiled1-2.o MSIL, which is stored in an assembly, as shown in FigureFigure 1-2When this code is executed (either in its own right if it is an executable or when it isused from other code) it mustas shown in Figure 1
33、-3.be compiledo native code using a JIT compiler,Figure 1-3The native code is executedrunning applications or prohe context of the managed CLR, along wises, as shown in Figure 1-4.ny otherFigure 1-4LinkingThere is one additional poto note concerning the preceding pros. The C# codet compileso MSIL in
34、 step 2 neednt be contained in a single file. It issible tosplit application code across multiple source code files, which are then compiledtogethero a single assembly. This pros is known as linking and is extremelyuseful. The reason for this ist it is far easier to work with several smaller filesno
35、ne enormous one. You can separate out logically related codeo an individual file,otten about when of code when yousot it can be worked on independently and then practically fcompleted. This also makes it much easier to locate specific pieneed them and enables of developers to divide up the programmi
36、ng burdenomanageable cks, where individuals can check out pieof code to work onwithout risking damage to otherwise satisfactory sections or sectionsare working on.t otheopleBeginning Visual C# 2005By Karli Watsonet al. Wrox Press 2006.NET Framework?.NET Framework 是由微軟開發(fā)的應(yīng)用程序創(chuàng)建的一個新的、性的。關(guān)于這個說法,最有趣的是我曾
37、經(jīng)是不明確的 - 但也有很好的理由。首先,請注意,我沒有說“開發(fā)Windows 操作系統(tǒng)上的應(yīng)用程序?!彪m然.NET Framework的版本微軟在Windows 操作系統(tǒng)上運行,它正在迅速成為可能找到替代版本,將工作的人。這方面的一個例子是 Mono,將.NET 框架(包括 C編譯器)將運行于多種操作系統(tǒng),包括Linux 和 Mac OS 的各式各樣的開源版本??赡苣阕x到這的時候,還有很多這樣的項目正在籌備中。此外,您可以在個人數(shù)字助理(PDA)類設(shè)備,甚至一些智能使用.NET Framework 精簡版(完整的.NET框架基本上是一個子集)。一個.NET 框架背后的關(guān)鍵激勵力是其預期用途為
38、整合不同操作系統(tǒng)的一種。此外,上面給出的.NET Framework 的定義包括那些沒有限制類的型應(yīng)用是可能的。這是因為沒有任何限制- 在.NET Framework 中允許創(chuàng)建Windows應(yīng)用程序,Web 應(yīng)用程序,Web 服務(wù)以及幾乎任何你能想到的。.NET 框架的設(shè)計,使得它可以應(yīng)用到任何語言。這其中包括本書的C,以及C +,Visual Basic 中,JScript 和更老的語言,比如COBOL。對于這項工作,這些語言的.NET版本也相繼出現(xiàn),而的是被了所有的時間。不僅所有的這些可使用.NET 框架中,但它們也可以相互通信。C開發(fā)用 Visual Basic 程序員寫的代碼這是完全
39、有可能,反之亦然。利所有這一切都提供了多功能性了前所未有不可水平,這也是.NETFramework 如此前景的一部分。.NET Framework 的?.NET 框架主要由代碼從您的客戶端使用的語言(如C),使用面象編程(OOP)技術(shù),一個巨大的庫。該庫分為不同的模塊 -你用它取決于你想要達到的結(jié)果部分。例如,一個模塊包含用于Windows 應(yīng)用程序,另一個用于網(wǎng)絡(luò)編程的,另一個用于 Web 開發(fā)的構(gòu)建塊。一些模塊分為更具體的子模塊,例如用于將模塊的 Web 開發(fā)中構(gòu)建 Web 服務(wù)的模塊。這里的意圖是為不同的操作系統(tǒng),以支持一些這些模塊的部分或全部,這取決于它們的特性。 PDA 的,例如,將
40、包括所有的能需要一些更深奧的模塊。.NET 功能的支持,但不太可在.NET Framework 類庫的一部分定義了一些基本類型。 A 型是數(shù)據(jù)的代表性,并指定一些最根本的,這些(如“32 位有符號整數(shù)”),便于使用.NET Framework語言之間的互操作性。這就是所謂的通用類型系統(tǒng)(CTS)。除了提供這個庫,框架還包括.NET 公共語言運行時(CLR),它負責庫開發(fā)的所有應(yīng)用程序的執(zhí)行。使用.NET我該怎樣使用.NET Framework 寫應(yīng)用程序?編寫使用.NET Framework 的應(yīng)用程序是指編寫代碼使用.NET 代碼庫(使用任何支持該框架的語言)。在這本書中,你使用 VS 的開
41、發(fā) - VS 是支持 C(以及托管和非托管的C +,Visual Basic 和其他一些人)的強大的集成開發(fā)環(huán)境。這種環(huán)境的優(yōu)點是易于與.NET 功能可以集成到您的代碼。您將要創(chuàng)建的代碼將完全C,但將在整個使用.NET 框架,而你使用的其他工具在 VS 必要時。為了使C代碼來執(zhí)行,它必須被轉(zhuǎn)換成目標操作系統(tǒng)能夠理解的語言,被稱為本機代碼。這種轉(zhuǎn)換稱為編譯代碼,由編譯程序進行的動作。在.NET 框架中,但是,這是一個兩階段的過MSIL 和 JIT當您編譯使用.NET Framework 的代碼庫,不立即創(chuàng)建操作系統(tǒng)特定的本地代碼。相反,你編譯你的代碼到中間語言(MSIL)代碼。這個代碼是不特定于
42、任何操作系統(tǒng),而不是專門針對 C。其他.NET 語言 - 例如,Visual Basic .NET中- 也編譯為這種語言作為第一階段。當您使用它來開發(fā)C應(yīng)用程序的編譯這一步是由 VS。顯然,要執(zhí)行的應(yīng)用程序的工作是必要的。這是一個剛剛在實時(JIT)編譯器,編譯成 MSIL 的本機代碼是特定于操作系統(tǒng)和計算機體系結(jié)構(gòu)正在有針對性的工作。僅在這一點上可以在 OS 執(zhí)行應(yīng)用程序。剛剛在時間部分的名稱這里反映出 MSIL 代碼只編譯為并在需要時。在過去,這是常常需要的代碼編譯成幾個應(yīng)用程序,其中每一個目標的一個特定的操作系統(tǒng)和 CPU 架構(gòu)。通常,這是最優(yōu)化的一種形式(獲取代碼的運行速度在 AMD
43、的組,例如),但有時這是的(對于應(yīng)用在這兩個 Win9x的和的WinNT/ 2000 環(huán)境中工作,例如)。這是現(xiàn)在沒有必要的,因為 JIT 編譯器(如它們的名稱所暗示的)使用 MSIL 代碼,它是獨立的計算機,操作系統(tǒng),和 CPU 的。數(shù)的 JIT 編譯器的存在,每個針對不同的體系結(jié)構(gòu),并且適當?shù)囊粋€將被用于創(chuàng)建所需的本機代碼。所有這一切的美妙之處在于它需要你少了很多的工作統(tǒng)相關(guān)的細節(jié)和專注于你的代碼更有趣的功能。-事實上,你可以忘掉系程序集當您編譯應(yīng)用程序,創(chuàng)建的 MSIL 代碼在一個。組件包括用于由其他應(yīng)用程序(其具有.dll 擴展名)使用,可以直接從Windows 中運行,而不需要任何其他的程序(這些具有.exe 文件擴展名)用于可執(zhí)行應(yīng)用程序文件和庫。以及含有 MSIL,組件還包含元信息(即,關(guān)于包含在組件中的信息,也被稱為元數(shù)據(jù)信息)和可選的資源
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 施工員的實習報告
- 小學班主任的年度工作總結(jié)(32篇)
- 幼兒園圣誕節(jié)的小活動策劃書(3篇)
- 晉升工程師工作總結(jié)
- 廣東省佛山市S6高質(zhì)量發(fā)展聯(lián)盟2024-2025學年高二上學期期中聯(lián)考 數(shù)學試卷含答案
- (一模)長春市2025屆高三質(zhì)量監(jiān)測(一)數(shù)學試卷
- 廣東省肇慶市(2024年-2025年小學五年級語文)人教版摸底考試(上學期)試卷及答案
- 2024年潔磁劑項目資金需求報告代可行性研究報告
- 上海市市轄區(qū)(2024年-2025年小學五年級語文)人教版期末考試((上下)學期)試卷及答案
- 上海市縣(2024年-2025年小學五年級語文)人教版摸底考試(上學期)試卷及答案
- 軋機安裝方案
- 義務(wù)教育《化學》課程標準(2022年版)
- 喉痹(咽炎)中醫(yī)護理方案
- DBJ33_T 1268-2022 工程建設(shè)工法編制標準
- 鋼結(jié)構(gòu)焊接施工記錄含內(nèi)容
- 治安保衛(wèi)重點要害部位審定表
- 壓力容器產(chǎn)品質(zhì)量證明書樣表簡版
- 小學檔案資料目錄
- 平方差公式(課堂PPT)
- 11工作審批流程及權(quán)限
- 昆蟲分類表匯總
評論
0/150
提交評論