顯示具有 C# 標籤的文章。 顯示所有文章
顯示具有 C# 標籤的文章。 顯示所有文章

2010年4月22日 星期四

Beginning Microsoft® Visual C#® 2008_Chapter_3_Variables and Expressions

Basic C# Syntax

  1. 一開始程式結構還有註解,跟Java沒啥不一樣,很快過去。
  2. C#有個特殊註解///,Chapter 31會解釋。

Basic C# Console Application Structure

  1. 主程式一樣是static void Main(string[] args)
  2. #region  #endregion 程式碼摺疊起來的時候,可以對該區域做一個註解,這註解會顯示在編輯視窗上面。

Variables

  1. < type > < name > ;

Simple Types

  1. numbers and Boolean
  2. the mechanics of storing numbers as a series of 0s and 1s in the memory of a computer
  3. TypeAlias ForAllowed Values
    sbyteSystem.SByteInteger between – 128 and 127
    byteSystem.ByteInteger between 0 and 255
    shortSystem.Int16Integer between – 32768 and 32767
    ushortSystem.UInt16Integer between 0 and 65535
    intSystem.Int32Integer between – 2147483648 and 2147483647
    uintSystem.UInt32Integer between 0 and 4294967295
    longSystem.Int64Integer between – 9223372036854775808 and 9223372036854775807
    ulongSystem.UInt64Integer between 0 and 18446744073709551615
  4. The u characters before some variable names are shorthand for unsigned
  5. three floating - point variable types: float , double , and decimal
  6. The first two store floating points in the form +/ – m × 2e , where the allowed values for m and e differ for each type.
  7. decimal uses the alternative form +/ – m × 10e .
  8. TypeAlias ForMin MMax MMin EMax EApprox. Min ValueApprox. Max Value
    floatSystem.Single0224-1491041.5 * 10 -453.4 * 10 38
    doubleSystem.Double0253-10759705.0 * 10 -3241.7 * 10 308
    decimalSystem.Decimal0296-2601.0 * 10 -287.9 * 10 28
  9. three other simple types:
  10. TypeAlias ForAllowed Values
    charSystem.CharSingle Unicode character, stored as an integer between 0 and 65535
    boolSystem.BooleanBoolean value, true or false
    stringSystem.StringA sequence of characters

Variable Naming

  1. basic rules:
    • The first character of a variable name must be either a letter, an underscore character ( _ ), or the at symbol ( @ ).
    • Subsequent characters may be letters, underscore characters, or numbers
  2. no keywords
  3. case sensitive

Naming Conventions

  1. Hungarian notation: placing a lowercase prefix on all variable names that identify the type
  2. it is far better to name variables appropriately for their purpose
  3. two naming conventions are used in the .NET Framework namespaces: PascalCase and camelCase .
  4. For your simple variables, stick to camelCase. Use PascalCase for certain more advanced naming, which is the Microsoft recommendation.

Beginning Microsoft® Visual C#® 2008_Chapter_2_Writing a C# Program

前半段介紹Visual Studio跟VCE,不太重要。
接下來是一個小練習,簡單的Console Application。主要目的只是熟悉VCE的環境。
第二個是簡單的Windows Form Application練習。
小心得:
Visual Studio說實在是挺好用的。

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