2010年4月22日 星期四

Beginning Microsoft® Visual C#® 2008_Chapter_1_Introducing C#

簡單介紹了.NET Framework和C#,以及幾個名詞,像是MSIL、JIT、CLR等,以及程式執行的基本流程。後面有Visual Studio的介紹,不是太重要就不管他了。
小心得:
很多換個名詞後,感覺就是Java哩。當然.NET Framework主要是針對微軟的東西設計的,所以我想細節理當會有很多不同,但以簡介來說,相似度高達90%。

What Is the .NET Framework?

  1. The .NET Framework has been designed so that it can be used from any language, including C# (the subject of this book) as well as C++, Visual Basic, JScript, and even older languages such as COBOL.
  2. .NET - specific versions of these languages have also appeared, and more are being released all the time.
  3. Not only do all of these have access to the .NET Framework, but they can also communicate with each other.

What's in the .NET Framework?

  1. The .NET Framework consists primarily of a gigantic library of code that you use from your client languages (such as C#) using object - oriented programming (OOP) techniques.
  2. Common Type System (CTS)
  3. .NET Common Language Runtime(CLR) : is responsible for maintaining the execution of all applications developed using the .NET library.

Writing Applications Using the .NET Framework

  1. In this book you use VS and VCE for your development
  2. VCE is a slimmed down (and free) version of VS that supports C# only.
  3. For C# code to execute, it must be converted into a language that the target operating system understands, known as native code . This conversion is called compiling code, an act that is performed by a compiler
  4. two - stage process

MSIL and JIT

  1. you compile your code into Microsoft Intermediate Language (MSIL) code.
  2. Just-in-Time (JIT) compiler: compiles MSIL into native code that is specific to the OS and machine architecture being targeted.Only at this point can the OS execute the application.

Assemblies

  1. When you compile an application, the MSIL code created is stored in an assembly .
  2. Assemblies include:
    • executable application files(.exe)
    • libraries(.dll)
    • meta information:information about the information contained in the assembly, also known as metadata
    • optional resources: additional data used by the MSIL, such as sound files and pictures
  3. Global Assembly Cache (GAC):  to place the reusable code in a place accessible to all applications.

Managed Code

  1. Code written using the .NET Framework is managed when it is executed (a stage usually referred to as runtime ).--the CLR looks after your applications by managing memory, handling security, allowing cross - language debugging, and so on.
  2. applications that do not run under the control of the CLR are said to be unmanaged --certain languages such as C++ can be used to write such applications, which, for example, access low - level functions of the operating system.
  3. in C# you can write only code that runs in a managed environment.

Garbage Collection

  1. inspecting the memory of your computer every so often and removing anything from it that is no longer needed
  2. Because this work is done for you at an unpredictable time, applications have to be designed with this in mind.Code that requires a lot of memory to run should tidy itself up, rather than wait for garbage collection to happen, but that isn’t as tricky as it sounds.

Fitting It Together

  1. Application code is written using a .NET - compatible language such as C#
  2. That code is compiled into MSIL, which is stored in an assembly
  3. When this code is executed (either in its own right if it is an executable or when it is used from other code), it must first be compiled into native code using a JIT compiler
  4. The native code is executed in the context of the managed CLR, along with any other running applications or processes

Linking

  1. It ’ s possible to split application code across multiple source code files, which are then compiled together into a single assembly.
  2. This extremely useful process is known as linking

What Is C#?

  1. is one of the languages you can use to create applications that will run in the .NET CLR.
  2. It is an evolution of the C and C++ languages
  3. the language syntax is simpler
  4. those features of C# that parallel the more advanced features of C++, such as directly accessing and manipulating system memory, can only be carried out using code marked as unsafe .
  5. C# being a type-safe language (unlike C++): once some data has been assigned to a type, it cannot subsequently transform itself into another unrelated type.
  6. the only language designed from the ground up for the .NET Framework

沒有留言: