c語言外文資料翻譯及原文_第1頁
已閱讀1頁,還剩13頁未讀 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領

文檔簡介

1、<p><b>  .NET和C#簡介</b></p><p>  為了理解.NET的重要性,考慮一下近10年來出現(xiàn)的許多Windows技術的本質(zhì)會有一定的幫助。盡管所有的Windows操作系統(tǒng)在表面上看來完全不同,但從Windows 3.1(1992年)到Windows Server 2003,在內(nèi)核上都有相同的Windows API。在我們轉(zhuǎn)而使用Windows的新版本時,AP

2、I中增加了非常多的新功能,但這是一個演化和擴展API的過程,并非是替換它。</p><p>  向后兼容性是Windows技術的極其重要的特性,也是Windows平臺的一個長處,但它有一個很大的缺點。每次某項技術進行演化,增加了新功能后,都會比它以前更復雜。</p><p>  很明顯,對此必須進行改進。Microsoft不可能一直擴展這些開發(fā)工具和語言,使它們越來越復雜,既要保證能跟上最

3、新硬件的發(fā)展步伐,又要與20世紀90年代初開始流行的Windows產(chǎn)品向后兼容。如果要得到一種簡單而專業(yè)化的語言、環(huán)境和開發(fā)工具,讓開發(fā)人員輕松地編寫優(yōu)秀的軟件,就需要一種新的開端。</p><p>  這就是C#和.NET的作用。粗略地說,.NET是一種在Windows上編程的新架構(gòu)—— 一種新API。C#是一種新語言,它可以利用.NET Framework及其開發(fā)環(huán)境中的所有新特性,以及在最近20年來出現(xiàn)的面

4、向?qū)ο蟮木幊谭椒ā?lt;/p><p>  在繼續(xù)介紹前,必須先說明,向后兼容性并沒有在這個演化進程中失去?,F(xiàn)有的程序仍可以使用,.NET也兼容現(xiàn)有的軟件。軟件組件在Windows上的通信,現(xiàn)在幾乎都是使用COM實現(xiàn)的。因此,.NET能夠提供現(xiàn)有COM組件的包裝器(wrapper),以便.NET組件與之通信。</p><p>  Microsoft已經(jīng)擴展了C++,提供了一種新語言J#,還對V

5、B進行了很多改進,把它轉(zhuǎn)變成為功能更強大的VB.NET,并允許把用這些語言編寫的代碼用于.NET環(huán)境。但這些語言都因有多年演化的痕跡,所以不能完全用現(xiàn)在的技術來編寫。</p><p>  在使用.NET Framework 1.0和Visual Studio .NET 2002時,要創(chuàng)建可移動應用程序,就必須下載Microsoft Mobile Internet Toolkit(MMIT)。而現(xiàn)在,有了.NET

6、Framework 1.1和Visual Studio .NET 2003,就可以直接創(chuàng)建可移動應用程序,不需要下載其他工具包了。</p><p>  在使用Visual Studio .NET 2003創(chuàng)建新項目時,這是顯而易見的。例如,在查看可以創(chuàng)建的C#項目類型列表時,會看到ASP.NET Mobile Web Application和Smart Device Application。ASP.NET Mob

7、ile Web Application項目類型可以用于建立基于Web的可移動應用程序。Smart Device Application項目類型可以創(chuàng)建用于Pocket PC或其他Windows CE設備的應用程序。為Windows CE設備建立的第三方客戶應用程序利用的是Compact Framework,這是.NET Framework的刪節(jié)版本。</p><p>  打開任何一種可移動項目類型,系統(tǒng)就會在Vi

8、sual Studio .NET工具箱中列出一組可用的可移動服務器控件,然后用戶就可以使用這些控件創(chuàng)建應用程序。</p><p>  在新的架構(gòu)中,另一個大的變化是ADO.NET。ADO.NET是訪問和處理數(shù)據(jù)的.NET方式,現(xiàn)在它有兩個新的數(shù)據(jù)提供程序,其中一個用于ODBC,另一個用于Oracle。</p><p>  在使用.NET Framework 1.0時,就可以使用ODBC數(shù)據(jù)

9、提供程序,但它需要單獨下載。另外,一旦下載,這個數(shù)據(jù)提供程序的命名空間就是Microsoft.Data.Odbc。</p><p>  而在.NET Framework 1.1中,ODBC數(shù)據(jù)提供程序是內(nèi)置的,不需要單獨下載。而且可以通過System.Data.Odbc命名空間來使用ODBC數(shù)據(jù)源,訪問ODBC數(shù)據(jù)連接、數(shù)據(jù)適配器和數(shù)據(jù)讀取器對象。</p><p>  另一個新的數(shù)據(jù)提供程

10、序用于處理Oracle數(shù)據(jù)庫。該數(shù)據(jù)庫在企業(yè)中的應用非常廣泛,缺乏Oracle數(shù)據(jù)提供程序常常是.NET進入企業(yè)的一大障礙。為了使用這個新的數(shù)據(jù)提供程序,需要在項目中引用System.Data.OracleClient命名空間。</p><p>  并發(fā)執(zhí)行side-by-side execution是指在同一個服務器上運行應用程序的多個版本,其中不同的應用程序版本使用不同的運行庫版本。Microsoft一直都向

11、開發(fā)人員承諾提供這個功能,但該功能總是很難可視化,因為只能使用Framework的一個版本。在發(fā)布了Framework的第2版.NET Framework 1.1后,就可以看到Microsoft提供的這個功能了?,F(xiàn)在,可以創(chuàng)建.NET應用程序面向.NET Framework 1.1的新版本,同時還可以讓面向.NET Framework 1.0的舊應用程序像以前那樣繼續(xù)運行。</p><p>  最近,許多Inte

12、rnet使用IP 4運行,IP4也稱為IPv4。它提供了IP地址,例如255.255.255. 255。.NET Framework 1.1現(xiàn)在支持IPv6,IPv6是在1995年創(chuàng)建的,解決了IPv4所面臨的許多問題。如果人們一直采用IPv4,將很快用盡可用的IP地址。</p><p>  .NET Framework 1.1通過System.Net命名空間支持IPv6,ASP.NET和XML Web服務也支持

13、IPv6。</p><p>  在升級.NET Framework時,還對Visual Studio .NET本身進行了升級。注意,在開始頁面上有一些新圖形,該頁面上對象的組織方式也有所不同。另外,新IDE最重大的變化是,一旦安裝,就不是簡單地把Visual Studio .NET 2002升級為Visual Studio .NET 2003,而是安裝了一個全新的IDE版本。如果機器上已經(jīng)安裝了Visual St

14、udio .NET 2002,就會得到兩個完全獨立的VS.NET IDE。這樣,如果要創(chuàng)建和使用面向.NET Framework 1.0的應用程序,就使用VS.NET 2002;如果要創(chuàng)建和使用面向.NET Framework 1.1的應用程序,就使用VS.NET 2003。</p><p>  還應注意,在打開用VS.NET 2002創(chuàng)建的項目時,系統(tǒng)會詢問是否要把項目升級為VS.NET 2003項目,如果回答

15、“是”,就會把項目升級為面向.NET Framework 1.1的應用程序。注意,這是一個不可逆的過程。</p><p>  除了這些較大的變化之外,在VS.NET 2003的IDE中,Intellisense的智能化程度更高,代碼自動完成功能更強。</p><p>  C#在某種程度上可以看作是.NET面向Windows環(huán)境的一種編程語言。在過去的十幾年里,Microsoft給Windo

16、ws和 Windows API添加了許多功能,VB和C++也經(jīng)歷了許多變化。雖然VB和C++最終已成為非常強大的語言,但這兩種語言也存在問題,因為它們保留了原來的一些內(nèi)容。</p><p>  對于Visual Basic來說,它的主要優(yōu)點是很容易理解,許多編程工作都很容易完成,基本上隱藏了Windows API和COM組件結(jié)構(gòu)的內(nèi)涵。其缺點是Visual Basic從來沒有實現(xiàn)真正意義上的面向?qū)ο?,所以大型應?/p>

17、程序很難分解和維護。另外,因為VB的語法繼承于BASIC的早期版本(BASIC主要是為了讓初學者更容易理解,而不是為了編寫大型商業(yè)應用程序),所以不能真正成為結(jié)構(gòu)化或面向?qū)ο蟮木幊陶Z言。</p><p>  另一方面,C++在ANSI C++語言定義中有其自己的根。它與ANSI不完全兼容,因為Microsoft是在ANSI定義標準化之前編寫C++編譯器的,但已經(jīng)相當接近了。遺憾的是,這導致了兩個問題。其一,ANS

18、I C++是在十幾年前的技術條件下開發(fā)的,因此不支持現(xiàn)在的概念(例如Unicode字符串和生成XML文檔),某些古老的語法結(jié)構(gòu)是為以前的編譯器設計的(例如成員函數(shù)的聲明和定義是分開的)。其二,Microsoft同時還試圖把C++演變?yōu)橐环N用于在Windows上執(zhí)行高性能任務的語言—— 在語言中避免添加大量Microsoft專用的關鍵字和各種庫。其結(jié)果是在Windows中,該語言成為了一種非常雜亂的語言。讓一個C++開發(fā)人員說說字符串有多

19、少個定義方式就可以說明這一點:char*、LPTSTR、string、CString (MFC 版本)、CString (WTL 版本)、wchar_t*和 OLECHAR*等。</p><p>  現(xiàn)在進入.NET時代—— 一種全新的環(huán)境,它對這兩種語言都進行了新的擴展。Microsoft給C++添加了許多Microsoft專用的關鍵字,并把VB演變?yōu)閂B.NET,保留了一些基本的VB語法,但在設計上完全不同,

20、從實際應用的角度來看,VB.NET是一種新語言。</p><p>  在這里,Microsoft決定給開發(fā)人員另一個選擇—— 專門用于.NET、具有新起點的語言, 即Visual C# .NET。Microsoft在正式場合把C#描述為一種簡單、現(xiàn)代、面向?qū)ο?、類型非常安全、派生于C和C++的編程語言。大多數(shù)獨立的評論員對其說法是“派生于C、 C++ 和Java”。這種描述在技術上是非常準確的,但沒有涉及到該語言

21、的真正優(yōu)點。從語法上看,C#非常類似于C++和Java,許多關鍵字都是相同的,C#也使用類似于C++和Java的塊結(jié)構(gòu),并用括號({})來標記代碼塊,用分號分隔各行語句。對C#代碼的第一印象是它非常類似于C++或Java代碼。但在這些表面上的類似性后面,C#學習起來要比C++容易得多,但比Java難一些。其設計與現(xiàn)代開發(fā)工具的適應性要比其他語言更高,它同時具有Visual Basic的易用性、高性能以及C++的低級內(nèi)存訪問性。C#包括以

22、下一些特性:</p><p>  完全支持類和面向?qū)ο缶幊?,包括接口和繼承、虛函數(shù)和運算符重載的處理。</p><p>  定義完整、一致的基本類型集。</p><p>  對自動生成XML文檔說明的內(nèi)置支持。</p><p>  自動清理動態(tài)分配的內(nèi)存。</p><p>  可以用用戶定義的特性來標記類或方法。這可以

23、用于文檔說明,對編譯有一定的影響(例如,把方法標記為只在調(diào)試時編譯)。</p><p>  對.NET基類庫的完全訪問權,并易于訪問Windows API。</p><p>  可以使用指針和直接內(nèi)存訪問,但C#語言可以在沒有它們的條件下訪問內(nèi)存。</p><p>  以VB的風格支持屬性和事件。</p><p>  改變編譯器選項,可以把程

24、序編譯為可執(zhí)行文件或.NET組件庫,該組件庫可以用與ActiveX控件(COM組件)相同的方式由其他代碼調(diào)用。</p><p>  C#可以用于編寫ASP.NET動態(tài)Web頁面和XML Web服務。</p><p>  應該指出,對于上述大多數(shù)特性,VB.NET和Managed C++也具備。但C#從一開始就使用.NET,對.NET特性的支持不僅是完整的,而且提供了比其他語言更合適的語法。

25、C#語言本身非常類似于Java,但其中有一些改進,因為Java并不是為應用于.NET環(huán)境而設計的。</p><p>  在結(jié)束這個主題前,還要指出C#的兩個局限性。其一是該語言不適用于編寫時間急迫或性能非常高的代碼,例如一個要運行1000或1050次的循環(huán),并在不需要這些循環(huán)時,立即清理它們所占用的資源。在這方面,C++可能仍是所有低級語言中的佼佼者。其二是C#缺乏性能極高的應用程序所需要的關鍵功能,包括保證在代

26、碼的特定地方運行的內(nèi)聯(lián)函數(shù)和析構(gòu)函數(shù)。但這類應用程序非常少。</p><p>  .NET運行在Windows 98、2000、XP和2003上,要使用.NET編寫代碼,需要安裝.NET SDK,除非使用內(nèi)置了.NET Framework 1.0和1.1的Windows Server 2003。除非要使用文本編輯器或其他第三方開發(fā)環(huán)境來編寫C#代碼,否則一般使用Visual Studio .NET 2003。運

27、行托管代碼不需要安裝完整的SDK,但需要.NET運行庫。需要把.NET運行庫分布到還沒有安裝它的客戶機上。</p><p>  .NET的語言無關性還有一些實際的限制。特別是中間語言在設計時就打算實現(xiàn)某些特殊的編程方法,這表示.NET語言必須與編程方法兼容,Microsoft為IL選擇的特定道路是傳統(tǒng)的面向?qū)ο蟮木幊?,帶有類的單一繼承性。</p><p>  除了傳統(tǒng)的面向?qū)ο缶幊掏?,中間

28、語言還引入了接口的概念,它們顯示了在帶有COM的Windows下的第一個實現(xiàn)方式。.NET接口與COM接口不同,它們不需要支持任何COM基礎結(jié)構(gòu),例如,它們不是派生自IUnknown,也沒有對應的GUID。但它們與COM接口共享下述理念:提供一個契約,實現(xiàn)給定接口的類必須提供該接口指定的方法和屬性的實現(xiàn)方式。</p><p>  前面介紹了使用.NET意味著要編譯為中間語言,即需要使用傳統(tǒng)的面向?qū)ο蟮姆椒▉砭幊獭?/p>

29、但這并不能提供語言的互操作性。畢竟,C++和Java都使用相同的面向?qū)ο蟮姆缎?,但它們?nèi)圆皇强山换ゲ僮鞯恼Z言。下面需要詳細探討一下語言互操作性的概念。</p><p>  首先,需要確定一下語言互操作性的含義。畢竟,COM允許以不同語言編寫的組件一起工作,即可以調(diào)用彼此的方法。這就足夠了嗎?COM是一個二進制標準,允許組件實例化其他組件,調(diào)用它們的方法或?qū)傩裕鵁o需考慮編寫相關組件的語言。但為了實現(xiàn)這個功能,每個

30、對象都必須通過COM運行庫來實例化,通過接口來訪問。根據(jù)關系組件的線程模型,不同線程上內(nèi)存空間和運行組件之間要編組數(shù)據(jù),這還可能造成很大的性能損失。在極端情況下,組件駐留在可執(zhí)行文件中,而不是DLL文件中,還必須創(chuàng)建單獨的過程來運行它們。重要的是組件要能與其他組件通信,但僅通過COM運行庫進行通信。無論COM是用于允許使用不同語言的組件直接彼此通信,或者創(chuàng)建彼此的實例,系統(tǒng)都把COM作為中間件來處理。不僅如此,COM結(jié)構(gòu)還不允許利用繼承

31、實現(xiàn),即它喪失了面向?qū)ο缶幊痰脑S多優(yōu)勢。</p><p>  與其他編程語言一樣,中間語言提供了許多預定義的基本數(shù)據(jù)類型。它的一個特性是值類型和引用類型有明顯的區(qū)別。對于值類型,變量直接保存其數(shù)據(jù),而對于引用類型,變量僅保存地址,對應的數(shù)據(jù)可以在該地址中找到。</p><p>  在C++中,引用類型類似于通過指針來訪問變量,而在Visual Basic中,與引用類型最相似的是對象,VB6

32、總是通過引用來訪問對象。中間語言也有數(shù)據(jù)存儲的規(guī)范:引用類型的實例總是存儲在一個名為托管堆的內(nèi)存區(qū)域中,值類型一般存儲在堆棧中(但如果值類型在引用類型中聲明為字段,它們就內(nèi)聯(lián)存儲在堆中)。</p><p>  .NET And C# Introduction</p><p>  In order to understand the significance of .NET, it is u

33、seful to remind ourselves of the nature of many of the Windows technologies that have appeared in the past ten years or so. Although they may look quite different on the surface, all of the Windows operating systems from

34、 Windows 3.1 (introduced in 1992) through Windows Server 2003 have the same familiar Windows API at their core. As we’ve progressed through new versions of Windows, huge numbers of new functions have been added to the AP

35、I, b</p><p>  While backward compatibility has been a crucial feature of Windows technologies and one of the strengths of the Windows platform, it does have a big disadvantage. Every time some technology evo

36、lves and adds new features, it ends up a bit more complicated than it was before.</p><p>  It was clear that something had to change. Microsoft couldn’t go on forever extending the same develop- ment tools a

37、nd languages, always making them more and more complex in order to satisfy the conflict- ing demands of keeping up with the newest hardware and maintaining backward compatibility with what was around when Windows first b

38、ecame popular in the early 1990s. There comes a point where you have to start with a clean slate if you want a simple yet sophisticated set of languages, environ- m</p><p>  This fresh start is what C# and .

39、NET are all about. Roughly speaking, .NET is a new framework—a new API—for programming on the Windows platform. Along with the .NET Framework, C# is a new lan- guage that has been designed from scratch to work with .NET,

40、 as well as to take advantage of all the progress in developer environments and in our understanding of object-oriented programming princi- ples that have taken place over the past 20 years.</p><p>  Before

41、we continue, we should make it clear that backward compatibility has not been lost in the pro- cess. Existing programs will continue to work, and .NET was designed with the ability to work with existing software. Communi

42、cation between software components on Windows presently almost entirely takes place using COM. Taking account of this, .NET does have the ability to provide wrappers around existing COM components so that .NET components

43、 can talk to them.</p><p>  It is true that you don’t need to learn C# in order to write code for .NET. Microsoft has extended C++, provided another new language called J#, and made substantial changes to Vi

44、sual Basic to turn it into the more powerful language Visual Basic .NET, in order to allow code written in either of these lan- guages to target the .NET environment. These other languages, however, are hampered by the l

45、egacy of having evolved over the years rather than having been written from the start with today’s te</p><p>  When using the .NET Framework 1.0 and Visual Studio .NET 2002, to be able to build mobile applic

46、a- tions you had to go out and download the Microsoft Mobile Internet Toolkit (MMIT). Now, with the .NET Framework 1.1 and Visual Studio .NET 2003, this is built right in and therefore no separate down- load is required.

47、</p><p>  This is all quite evident when you create a new project using Visual Studio .NET 2003. For instance, when you look at the list of available C# project types you can create, you will find ASP.NET Mo

48、bile Web Application and Smart Device Application. You would use the ASP.NET Mobile Web Application project type to build Web-based mobile applications (as the name describes). Building a Smart Device Application allows

49、you to create applications for the Pocket PC or any other Windows CE device. The th</p><p>  Opening one of these mobile project types, you will then be presented with a list of available mobile server contr

50、ols in the Visual Studio .NET Toolbox that you can then use to build your applications.</p><p>  Another big area of change in the framework is to ADO.NET. ADO.NET, the .NET way of accessing and working with

51、 data, now has two new data providers—one for ODBC and another for Oracle.</p><p>  An ODBC data provider was available when working with the .NET Framework 1.0, but this required a separate download. Also,

52、once downloaded, the namespace for this data provider was Microsoft.Data.Odbc.</p><p>  With the .NET Framework 1.1, the ODBC data provider is built right in, and no separate download is required. You will n

53、ow be able to work with ODBC data sources through the System.Data.Odbc namespace. This also gives you access to ODBC data connection, data adapter, and data reader objects.</p><p>  The other new data provid

54、er is for working with Oracle databases. This database is quite popular in the enterprise space, and the lack of an Oracle data provider often times was a big barrier for .NET to enter this space. To work with this new d

55、ata provider, you will need to make a reference to the System.Data.OracleClient namespace in your project.</p><p>  Side-by-side execution is the ability to run multiple versions of an application on the sam

56、e server where different application versions target different runtime versions. This was always promised to us as developers, but it was always hard to visualize as only one version of the framework was available. With

57、the release of a second version of the framework (.NET Framework 1.1), we can actually see that it is possible to have this capability. Therefore, you can build new versions of your .NET ap</p><p>  Presentl

58、y, much of the Internet runs using IP version 4, also referred to as IPv4. IPv4 gives us IP addresses such as 255.255.255.255. The .NET Framework 1.1 now supports IPv6, which was created in 1995 to address many of the pr

59、oblems that the world was facing with IPv4. Most of the problems deal with the fact that by the world’s continual use of IPv4, we are rapidly running out of available IP addresses.</p><p>  IPv6 is supported

60、 in the .NET Framework 1.1 through the System.Net namespace as well as in ASP.NET and XML Web services.</p><p>  Along with the upgrade to the .NET Framework, Visual Studio .NET itself has also undergone an

61、upgrade. You will notice that there are some new graphics on the Start Page available and that things on this page are organized a little differently. Besides that, the biggest thing to notice with this new IDE is that o

62、nce installed, it does not simply upgrade Visual Studio .NET 2002 to Visual Studio .NET 2003.</p><p>  Instead, it installs a completely new version of the IDE, and if you already have VS.NET 2002 on your ma

63、chine, then you will have two complete VS.NET IDEs on your box. The reason for this is so that if you want to build and work with applications that target the .NET Framework version 1.0, then you will use VS.NET 2002, an

64、d if you want to build and work with applications that target the .NET Framework ver- sion 1.1 then you will use VS.NET 2003.</p><p>  You should also be aware that when you open a project that was built usi

65、ng VS.NET 2002, you will be asked if you want to upgrade the project to be a VS.NET 2003 project. Doing this will then cause the pro- ject to be re-targeted at the .NET Framework 1.1. Be careful about doing this as it is

66、 an irreversible process.</p><p>  Besides these big changes, you will find that VS.NET 2003 is a better IDE with smarter Intellisense and code completion.</p><p>  In one sense, C# can be seen

67、as being the same thing to programming languages as .NET is to the Windows environment. Just as Microsoft has been adding more and more features to Windows and the Windows API over the past decade, Visual Basic and C++ h

68、ave undergone expansion. Although Visual Basic and C++ have ended up as hugely powerful languages as a result of this, both languages also suf- fer from problems due to the legacies of how they have evolved.</p>&

69、lt;p>  In the case of Visual Basic 6 and earlier, the main strength of the language was the fact that it was simple to understand and didn’t make many programming tasks easy, largely hiding the details of the Windows

70、API and the COM component infrastructure from the developer. The downside to this was that Visual Basic was never truly object-oriented, so that large applications quickly become disorganized and hard to maintain. As wel

71、l as this, because Visual Basic’s syntax was inherited from early vers</p><p>  C++, on the other hand, has its roots in the ANSI C++ language definition. It isn’t completely ANSI- compliant for the simple r

72、eason that Microsoft first wrote its C++ compiler before the ANSI definition had become official, but it comes close. Unfortunately, this has led to two problems. First, ANSI C++ has its roots in a decade-old state of te

73、chnology, and this shows up in a lack of support for modern concepts(such as Unicode strings and generating XML documentation), and in some archaic synta</p><p>  Now enter .NET—a completely new environment

74、that is going to involve new extensions to both lan- guages. Microsoft has gotten around this by adding yet more Microsoft-specific keywords to C++, and by completely revamping Visual Basic into Visual Basic .NET, a lang

75、uage that retains some of the basic VB syntax but that is so different in design that we can consider it to be, for all practical purposes, a new language.</p><p>  It’s in this context that Microsoft has de

76、cided to give developers an alternative—a language designed specifically for .NET, and designed with a clean slate. Visual C# .NET is the result. Officially, Microsoft describes C# as a “simple, modern, object-oriented,

77、and type-safe programming language derived from C and C++.” Most independent observers would probably change that to “derived from C, C++, and Java.” Such descriptions are technically accurate but do little to convey the

78、 beauty or eleganc</p><p>  Full support for classes and object-oriented programming, including both interface and imple- mentation inheritance, virtual functions, and operator overloading.</p><p&

79、gt;  A consistent and well-defined set of basic types.</p><p>  Built-in support for automatic generation of XML documentation.</p><p>  Automatic cleanup of dynamically allocated memory.</p&

80、gt;<p>  The facility to mark classes or methods with user-defined attributes. This can be useful for doc- umentation and can have some effects on compilation (for example, marking methods to be compiled only in d

81、ebug builds).</p><p>  Full access to the .NET base class library, as well as easy access to the Windows API (if you really need it, which won’t be all that often).</p><p>  Pointers and direct

82、memory access are available if required, but the language has been designed in such a way that you can work without them in almost all cases.</p><p>  Support for properties and events in the style of Visual

83、 Basic.</p><p>  Just by changing the compiler options, you can compile either to an executable or to a library of .NET components that can be called up by other code in the same way as ActiveX controls(COM

84、components).</p><p>  C# can be used to write ASP.NET dynamic Web pages and XML Web services.</p><p>  Most of the above statements, it should be pointed out, do also apply to Visual Basic .NET

85、and Managed C++. The fact that C# is designed from the start to work with .NET, however, means that its support for the features of .NET is both more complete, and offered within the context of a more suitable syntax tha

86、n for those other languages. While the C# language itself is very similar to Java, there are some improve- ments: in particular, Java is not designed to work with the .NET environment.</p><p>  Before we lea

87、ve the subject, we should point out a couple of limitations of C#. The one area the language is not designed for is time-critical or extremely high performance code—the kind where you really are worried about whether a l

88、oop takes 1,000 or 1,050 machine cycles to run through, and you need to clean up your resources the millisecond they are no longer needed. C++ is likely to continue to reign supreme among low-level languages in this area

89、. C# lacks certain key facilities needed for ex</p><p>  .NET will run on Windows 98, 2000, XP, and 2003. In order to write code using .NET, you will need to install the .NET SDK unless you are using Windows

90、 Server 2003, which comes with the .NET Framework 1.0 and 1.1 already installed. Unless you are intending to write your C# code using a text editor or some other third party developer environment, you will almost certain

91、ly also want Visual Studio .NET 2003. The full SDK isn’t needed to run managed code, but the .NET runtime is needed. You may find </p><p>  The language independence of .NET does have some practical limitati

92、ons. IL is inevitably going to imple- ment some particular programming methodology, which means that languages targeting it are going to have to be compatible with that methodology. The particular route that Microsoft ha

93、s chosen to follow for IL is that of classic object-oriented programming, with single implementation inheritance of classes.</p><p>  Besides classic object-oriented programming, IL also brings in the idea o

94、f interfaces, which saw their first implementation under Windows with COM. .NET interfaces are not the same as COM interfaces; they do not need to support any of the COM infrastructure (for example, they are not derived

95、from IUnknown, and they do not have associated GUIDs). However, they do share with COM interfaces the idea that they provide a contract, and classes that implement a given interface must provide implementati</p>&

96、lt;p>  We have now seen that working with .NET means compiling to IL, and that in turn means that you will need to use traditional object-oriented methodologies. However, that alone is not sufficient to give us langua

97、ge interoperability. After all, C++ and Java both use the same object-oriented paradigms, but they are still not regarded as interoperable. We need to look a little more closely at the concept of language interoperabilit

98、y.</p><p>  To start with, we need to consider exactly what we mean by language interoperability. After all, COM allowed components written in different languages to work together in the sense of calling eac

99、h other’s methods. What was inadequate about that? COM, by virtue of being a binary standard, did allow compo- nents to instantiate other components and call methods or properties against them, without worrying about the

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 眾賞文庫僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論