c#文獻(xiàn)翻譯---c#的優(yōu)點(diǎn)_第1頁
已閱讀1頁,還剩6頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、<p><b>  C#的優(yōu)點(diǎn)</b></p><p>  C#在某種程度上可以看作是.NET面向Windows環(huán)境的一種編程語言。在過去的十幾年里,Microsoft給Windows和 Windows API添加了許多功能,VB和C++也經(jīng)歷了許多變化。雖然VB和C++最終已成為非常強(qiáng)大的語言,但這兩種語言也存在問題,因?yàn)樗鼈儽A袅嗽瓉淼囊恍﹥?nèi)容。</p><

2、p>  對(duì)于Visual Basic來說,它的主要優(yōu)點(diǎn)是很容易理解,許多編程工作都很容易完成,基本上隱藏了Windows API和COM組件結(jié)構(gòu)的內(nèi)涵。其缺點(diǎn)是Visual Basic從來沒有實(shí)現(xiàn)真正意義上的面向?qū)ο?,所以大型?yīng)用程序很難分解和維護(hù)。另外,因?yàn)閂B的語法繼承于BASIC的早期版本(BASIC主要是為了讓初學(xué)者更容易理解,而不是為了編寫大型商業(yè)應(yīng)用程序),所以不能真正成為結(jié)構(gòu)化或面向?qū)ο蟮木幊陶Z言。</p>

3、;<p>  另一方面,C++在ANSI C++語言定義中有其自己的根。它與ANSI不完全兼容,因?yàn)镸icrosoft是在ANSI定義標(biāo)準(zhǔn)化之前編寫C++編譯器的,但已經(jīng)相當(dāng)接近了。遺憾的是,這導(dǎo)致了兩個(gè)問題。其一,ANSI C++是在十幾年前的技術(shù)條件下開發(fā)的,因此不支持現(xiàn)在的概念(例如Unicode字符串和生成XML文檔),某些古老的語法結(jié)構(gòu)是為以前的編譯器設(shè)計(jì)的(例如成員函數(shù)的聲明和定義是分開的)。其二,Micros

4、oft同時(shí)還試圖把C++演變?yōu)橐环N用于在Windows上執(zhí)行高性能任務(wù)的語言—— 在語言中避免添加大量Microsoft專用的關(guān)鍵字和各種庫。其結(jié)果是在Windows中,該語言成為了一種非常雜亂的語言。讓一個(gè)C++開發(fā)人員說說字符串有多少個(gè)定義方式就可以說明這一點(diǎn):char*、LPTSTR、string、CString (MFC 版本)、CString (WTL 版本)、wchar_t*和 OLECHAR*等。</p>&

5、lt;p>  現(xiàn)在進(jìn)入.NET時(shí)代—— 一種全新的環(huán)境,它對(duì)這兩種語言都進(jìn)行了新的擴(kuò)展。Microsoft給C++添加了許多Microsoft專用的關(guān)鍵字,并把VB演變?yōu)閂B.NET,保留了一些基本的VB語法,但在設(shè)計(jì)上完全不同,從實(shí)際應(yīng)用的角度來看,VB.NET是一種新語言。</p><p>  在這里,Microsoft決定給開發(fā)人員另一個(gè)選擇—— 專門用于.NET、具有新起點(diǎn)的語言, 即Visual

6、C# .NET。Microsoft在正式場合把C#描述為一種簡單、現(xiàn)代、面向?qū)ο?、類型非常安全、派生于C和C++的編程語言。大多數(shù)獨(dú)立的評(píng)論員對(duì)其說法是“派生于C、 C++ 和Java”。這種描述在技術(shù)上是非常準(zhǔn)確的,但沒有涉及到該語言的真正優(yōu)點(diǎn)。從語法上看,C#非常類似于C++和Java,許多關(guān)鍵字都是相同的,C#也使用類似于C++和Java的塊結(jié)構(gòu),并用括號(hào)({})來標(biāo)記代碼塊,用分號(hào)分隔各行語句。對(duì)C#代碼的第一印象是它非常類似于

7、C++或Java代碼。但在這些表面上的類似性后面,C#學(xué)習(xí)起來要比C++容易得多,但比Java難一些。其設(shè)計(jì)與現(xiàn)代開發(fā)工具的適應(yīng)性要比其他語言更高,它同時(shí)具有Visual Basic的易用性、高性能以及C++的低級(jí)內(nèi)存訪問性。C#包括以下一些特性:</p><p>  完全支持類和面向?qū)ο缶幊?,包括接口和繼承、虛函數(shù)和運(yùn)算符重載的處理。</p><p>  定義完整、一致的基本類型集。&l

8、t;/p><p>  對(duì)自動(dòng)生成XML文檔說明的內(nèi)置支持。</p><p>  自動(dòng)清理動(dòng)態(tài)分配的內(nèi)存。</p><p>  可以用用戶定義的特性來標(biāo)記類或方法。這可以用于文檔說明,對(duì)編譯有一定的影響(例如,把方法標(biāo)記為只在調(diào)試時(shí)編譯)。</p><p>  對(duì).NET基類庫的完全訪問權(quán),并易于訪問Windows API。</p>

9、<p>  可以使用指針和直接內(nèi)存訪問,但C#語言可以在沒有它們的條件下訪問內(nèi)存。</p><p>  以VB的風(fēng)格支持屬性和事件。</p><p>  改變編譯器選項(xiàng),可以把程序編譯為可執(zhí)行文件或.NET組件庫,該組件庫可以用與ActiveX控件(COM組件)相同的方式由其他代碼調(diào)用。</p><p>  C#可以用于編寫ASP.NET動(dòng)態(tài)Web頁面和X

10、ML Web服務(wù)。</p><p>  應(yīng)該指出,對(duì)于上述大多數(shù)特性,VB.NET和Managed C++也具備。但C#從一開始就使用.NET,對(duì).NET特性的支持不僅是完整的,而且提供了比其他語言更合適的語法。C#語言本身非常類似于Java,但其中有一些改進(jìn),因?yàn)镴ava并不是為應(yīng)用于.NET環(huán)境而設(shè)計(jì)的。</p><p>  在結(jié)束這個(gè)主題前,還要指出C#的兩個(gè)局限性。其一是該語言不適

11、用于編寫時(shí)間急迫或性能非常高的代碼,例如一個(gè)要運(yùn)行1000或1050次的循環(huán),并在不需要這些循環(huán)時(shí),立即清理它們所占用的資源。在這方面,C++可能仍是所有低級(jí)語言中的佼佼者。其二是C#缺乏性能極高的應(yīng)用程序所需要的關(guān)鍵功能,包括保證在代碼的特定地方運(yùn)行的內(nèi)聯(lián)函數(shù)和析構(gòu)函數(shù)。但這類應(yīng)用程序非常少。</p><p>  出處:Professional C#Third Edition</p><p&

12、gt;  作者:Simon Robinson</p><p>  Christian Nagel</p><p><b>  Jay Glynn</b></p><p>  Morgan Skinner</p><p>  Karli Watson</p><p>  Bill Evjen<

13、/p><p>  Where C# Fits In</p><p>  In one sense, C# can be seen as being the same thing to programming languages as .NET is to the Windows environment. Just as Microsoft has been adding more and mo

14、re features to Windows and the Windows API over the past decade, Visual Basic and C++ have undergone expansion. Although Visual Basic and C++ have ended up as hugely powerful languages as a result of this, both languages

15、 also suffer from problems due to the legacies of how they have evolved.</p><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 an

16、d didn’t make many programming tasks easy, largely hiding the details of the Windows API and the COM component infrastructure from the developer. The downside to this was that Visual Basic was never truly object-oriented

17、, so that large applications quickly become disorganized and hard to maintain. As well as this, because Visual Basic’s syntax was inherited from early vers</p><p>  C++, on the other hand, has its roots in t

18、he ANSI C++ language definition. It isn’t completely ANSIcompliant for the simple reason that Microsoft first wrote its C++ compiler before the ANSI definition had become official, but it comes close. Unfortunatel

19、y, this has led to two problems. First, ANSI C++ has its roots in a decade-old state of technology, and this shows up in a lack of support for modern concepts (such as Unicode strings and generating XML documentation), a

20、nd in some archaic</p><p>  The result is that on Windows, the language has become a complete mess. Just ask C++ developers how many definitions for a string they can think of: char*, LPTSTR, string, CString

21、 (MFC version), CString (WTL version), wchar_t*, OLECHAR*, and so on.</p><p>  Now enter .NET—a completely new environment that is going to involve new extensions to both languages. Microsoft has gotten arou

22、nd this by adding yet more Microsoft-specific keywords to C++, and by completely revamping Visual Basic into Visual Basic .NET, a language that retains some of the basic VB syntax but that is so different in design that

23、we can consider it to be, for all practical purposes, a new</p><p>  language. It’s in this context that Microsoft has decided to give developers an alternative—a language designed specifically for .NET, and

24、 designed with a clean slate. Visual C# .NET is the result. Officially, Microsoft describes C# as a “simple, modern, object-oriented, and type-safe programming language derived from</p><p>  C and C++.” Most

25、 independent observers would probably change that to “derived from C, C++, and Java.” Such descriptions are technically accurate but do little to convey the beauty or elegance of the language. Syntactically, C# is very s

26、imilar to both C++ and Java, to such an extent that many keywords are the same, and C# also shares the same block structure with braces ({}) to mark blocks of code, and semicolons to separate statements. The first impres

27、sion of a piece of C# code is that it looks </p><p>  ? Full support for classes and object-oriented programming, including both interface and implementation</p><p>  inheritance, virtual functi

28、ons, and operator overloading.</p><p>  ? A consistent and well-defined set of basic types.</p><p>  ? Built-in support for automatic generation of XML documentation.</p><p>  ? Aut

29、omatic cleanup of dynamically allocated memory.</p><p>  ? The facility to mark classes or methods with user-defined attributes. This can be useful for documentation</p><p>  and can have some e

30、ffects on compilation (for example, marking methods to be</p><p>  compiled only in debug builds).</p><p>  ? Full access to the .NET base class library, as well as easy access to the Windows AP

31、I (if you</p><p>  really need it, which won’t be all that often).</p><p>  ? Pointers and direct memory access are available if required, but the language has been designed</p><p>

32、  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 Basic.</p><p>  ? Just by changing the compiler options, y

33、ou can compile either to an executable or to a library of</p><p>  .NET components that can be called up by other code in the same way as ActiveX controls</p><p>  (COM components).</p>&

34、lt;p>  ? C# can be used to write ASP.NET dynamic Web pages and XMLWeb services.</p><p>  Most of the above statements, it should be pointed out, do also apply to Visual Basic .NET and Managed C++. The fac

35、t 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 than</p><p>  

36、for those other languages. While the C# language itself is very similar to Java, there are some improvements:</p><p>  in particular, Java is not designed to work with the .NET environment.</p><p&

37、gt;  Before we leave 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

38、 about whether a loop 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 lang

39、uages in this area. C# lacks certain key facilities needed for ex</p><p>  出處:Professional C#Third Edition</p><p>  作者:Simon Robinson</p><p>  Christian Nagel</p><p>&l

溫馨提示

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

評(píng)論

0/150

提交評(píng)論