【正文】
rk 提供的類是開發(fā)人員日常經(jīng)驗(他們占了這本書很大一部分內(nèi)容)的一個極其重要的組成部分。 一些類的功能的特點是圍繞底層的 OS 的包裝,例如有用于訪問文件系統(tǒng)的類,并使用網(wǎng)絡(luò)功能如接口。 } } 我們將在適當?shù)臅r 候檢查所有組件,但現(xiàn)在,即使是這個最簡單的例子也需要調(diào)用庫中的類(這個例子中的 類)來做這個工作。 這三類劃分并不嚴格,不少類適合一分為二。因此,這里的三個類別是不嚴格。顧名思義, .NET Framwork 不只是支持一種編程語言,而是支持 多種語言服務(wù)的 .NET 框架類庫。 擴展是經(jīng)過深思熟慮 的并且工作的很好 , 但是所調(diào)用 .NET 庫的代碼與 C++并不相同。 但 C#在這方面 并不是 獨樹一幟 的 。 NET 語言像 VB 的語法,而不是 VB 6 中。這是一個功能性編程語言,嚴重影響由毫升語言。然而,與許多 語言功能,使一些困難的問題更容易的成本是很多在更傳統(tǒng)的語言很容易的事情是有顯著努力,在 F# 功能性語言,善于在復(fù)雜的問題,但可以用簡單的笨拙的。然而,有微妙的區(qū)別在于:在語言哲學(xué)超越語法。例 12 顯示了一個簡單查詢 的功能 。 為了使用 此語法, C# 中添加了一個語言功能結(jié)合,讓筏代碼這種不只是用于數(shù)據(jù)庫訪問,而且還為 XML 解析,或工作對象模型。這一個實驗的語法允許內(nèi)嵌 XML,用編譯成代碼,建立模型來來表該 XML的方法。 它還以一種微妙的方式不直接訪問調(diào)用類庫而提供服務(wù) 。這 CLR 的。這當然是從 C 和 C+ +的工作與不同這些語言編譯器的輸出可以直接執(zhí)行,由計算機和雖然這些語言有一定的運行服務(wù),它可以編寫代碼,沒有他們可以運 行。相反,它們產(chǎn)生中間形式的代碼稱為白細胞介素,中間語言運行時決定。 NET 運行時,可以提供有用的服務(wù),這都很難傳統(tǒng)的編譯系統(tǒng)要貫徹落實好。靈活裝載了強大的支持服務(wù)和版本的共享組件的機制 。事實上,一個受歡迎的,但有些無知的 “笑話 ”欠周到的 Java 社區(qū)成員之間形容為一個貧窮的 C#仿爪哇。例如,第三方組件和工具 的廣泛可用性平臺明顯 更具吸引力。 如果你正在編寫一個特定的操作系統(tǒng)上運行的代碼,它不是特別有用語言獨特的工具和組件的削減你到您選擇平臺。 NET 包裝,工作能力等非托管功能直接從托管代碼是無價的。 NET 代碼在 Linux 上運行,以及相關(guān)的 Moonlight 項目是一個開源版本的Silverlight。 最新版本的 C#包含的功能,提高能力,進一步。因此,而不是致力于新功能的部分或全部章節(jié),我們將介紹他們在情況下, 適當?shù)嘏c其他舊的語言功能集成。例如,可以考慮在示例 13 C# 的代碼,使用部分 Office對象模型讀取 Word 文檔的作者屬性。 C , .NET 4, and Visual Studio 2020 | 7 Download from Library of Wow! eBook object readOnly = true。 object authorProp = (Item, | ,null, docProperties,new object[] { Author })。 (ref saveChanges, ref missing, ref missing)。 C# 中 并 不能夠做到這一點,所以開發(fā)商 不得不手動做這些所有的工作 。 C 現(xiàn)在能夠為我們填補所有的細節(jié),這要歸功于它新的動態(tài)語言功能。 string authorName = docProperties[Author].Value。} } We’ll examine all the pieces shown here in due course, but for now, note that even this simplest of examples depends on a class from the librarythe class in this caseto do its job. Finally, the class library offers whole frameworks to support building certain kinds of applications. For example, Windows Presentation Foundation (WPF) is a framework for building Windows desktop software。 flexible mechanisms for loading shared ponents with robust support for servicing and versioning。 object missing = 。 Type docPropType = ()。 object saveChanges = false。 doc = (, ReadOnly: true)。 (authorName)。 string authorName = docProperties[Author].Value。 (authorName)。 Type propType = ()。 doc = (ref fileName, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing)。 and as already mentioned, the CLR’s ability to verify that code conforms to type safety rules before executing it, ruling out whole classes of security and stability bugs. If you’re a Java developer, all of this will sound rather familiar— just substitute bytecode for IL and the story is very similar. Indeed, a popular but somewhat ignorant “joke” among the less thoughtful members of the Java munity is to describe C as a poor imitation of Java. When the first version of C appeared, the differences were subtle, but the fact that Java went on to copy several features from C illustrates that C was always more than a mere clone. The languages have grown more obviously different with each new version, but one difference, present from the start, is particularly important for Windows developers: C has always made it easy to get at the features of the underlying Windows platform. Continuity and the Windows Ecosystem Software development platforms do not succeed purely on their own meritscontext matters. For example, widespread availability of thirdparty ponents and tools can make a platform significantly more pelling. Windows is perhaps the most striking example of this phenomenon. Any new programming system attempting to gain acceptance has a considerable advantage if it can plug into some existing ecosystem, and one of the biggest differences between C and Java is that C and the .NET Framework positively embrace the Windows platform, while Java goes out of its way to insulate developers from the underlying OS. If you’re writing code to run on a specific operating system, it’s not especially helpful for a language to cut you off from the tools and ponents unique to your chosen platform. Rather than requiring developers to break with the past, .NET offers continuity by making it possible to work directly with ponents and services either built into or built for Windows. Most of the time, you won’t need to use thisthe class library provides wrappers for a lot of the underlying platform’s functionality. However, if you need to use a thirdparty ponent or a feature of the operating system that doesn’t yet have a .NET wrapper, the ability to work with such unmanaged features directly from managed code is invaluable. While .NET offers features to ease integration with the underlying platform, there is still support for nonWindows systems. Microsoft’s Silverlight can run C and code on Mac OS X as well as Windows. There’s an open source project called Mono which enables .NET code to run on Linux, and the related Moonlight project is an open source version of Silverlight. So the presence of local platform integration features doesn’t stop C from being useful on multiple platformsif you want to target multiple operating systems, you would just choose not to use any platformspecific features. So the biggest philosophical difference between C and Java is that C provides equal support for direct use of operatingsystemspecific features and for platform independence. Java makes the former disproportionately harder than the latter. The latest version of C contain