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.

沒有留言: