Study Note:CSIN3 Chapter 2: C# Language Basic

 
I should familiar with this chapter. If not, I should hit the wall.
 
2.1 A First C# Program
I'm very glad to see the first C# program is not a hello world program. :-)
The first program introduce the variable, method, Main, Class, Namespace.
Nothing important to me, I think.
 
2.2 Syntax
Identifiers: The name of the class, method, variable, namespace and so on. Start with Unicode character or under score. C# is case-sensitive.
Keywords: The words system choose which can't be an identifier, reserved word. You can use prefix @ to use a keyword as identifier. Then you can use it like "@class". But if you use prefix @ to a common identifier, the "@a" and "a" is the same.
Contextual Keywords: I don't know it exactly, maybe they are recognized as keywords in special area.
Literals: Data in the code.
Punctuators: Separator. E.g. , ; {}
Operators: Transform and combine expressions. E.g. + - * /
Comments: // single line comment /* */ multiline comment
 
I decide to not note all the things, it is too much to note, oops. I just note the useful information.
 
2.3 Type Basics
  1. Predefine types and Custom types
  2. Value types, Reference types and Pointer types
    • Different of value type and reference type
      • Memory allocate: value just an object, reference has a reference and an object
      • Copy: value copy the object, reference copy the reference means point the same object
     
  3. Struct is a Custom Value type
 
2.4 Numeric Types
Numeric Literal inference: I use to think is totally wrong.
If there is a decimal point then the literal is a double , else it is a int or long and so on
Checked and Unchecked operator
Real number rounding error: see some statements
decimal m = 1M / 6M;               // 0.1666666666666666666666666667M
double d = 1.0 / 6.0;             // 0.16666666666666666
decimal notQuiteWholeM = m+m+m+m+m+m; // 1.0000000000000000000000000002M
double notQuiteWholeD = d+d+d+d+d+d; // 0.99999999999999989
So don't use float or double to financial calculation, I think.
 
2.5 Boolean Type and Operators
Bool alias System.Boolean
Bool value can't convert to numeric types
Condition operators(&& || !) short-circuit evaluation when possible, &, | don't do short-circuit evaluation
 
2.6 Strings and Characters
Escape characters: /u Unicode
@: verbatim string
 
2.7 Arrays
Declaration:
C#: int[] array = new int[5]; In actually, int[] array is declaration, and new int[5] is initialize
C++: int array[5];
Default initialize: value type 0 or false and so on, reference type is null
Multidimensional array:
rectangular array: int[,] array = new int[3,3];
Jagged Array: int[][] array = new int[3][]; array[0] = new int[4];
Var: I think it will be introduce more in later chapter
 
2.8 Variables and Parameters
Memory allocate: stock and heap
Stock: local variables and parameters
Heap: New objects
Definite Assignment:
  • Local variables must be assigned a value before they can be read.
  • Function arguments must be supplied when a method is called.
  • All other variables (such as fields and array elements) are automatically initialized by the runtime.
Default Value:
Reference null
Numeric type or Enum type 0
char type '/0'
bool type false
Parameter pass style
None
 Value
Going in
Ref
 Reference
Going in
Out
 Reference
Going out
 
 
2.9 Expression and Operators
Operator Precedence
 
2.10 Statements
Goto in switch
Goto case 12;
 
2.11 Namespace
Some advantage feature: I don't think it is very import, and I don't know some of them well, NEED TO READ AGAIN
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值