標籤:
TYPE(類型)
1.C#中所有變數和對象都需要明確地聲明其類型,除了關鍵字var是隱含類型。
2.只能將範圍小的變數賦值給範圍大的變數,雖然反過來賦值也能編譯通過,但可能會出bug。
Escape characters(逸出字元)
Char Meaning
\‘Single quote
\"Double quote
\\ Backslash
\0Null
\aAlert
\bBackspace
\fForm feed
\nNewline
\rCarriage return
\tHorizontal tab
\vVertical tab
branches and looping
1.C#和其他語言不同之處,無論是if還是while,for之後的括弧裡必須是一個布林運算式。
2.foreach的用法,不多說直接上代碼
static void Main(string[] args) {
foreach (string inarg in args) {
Console.WriteLine(“{0} {1}”, inarg, inarg.Length );
}
}
3.continue and break
continue:停止當前迴圈並從迴圈開始出執行迴圈
break:跳出迴圈執行下面的代碼
Classes and Objects
面試常問的問題:opp的三大特點是什麼,或三大支柱是什麼,答Encapsulation(封裝),Polymorphism(多態)和Inheritance(繼承)
1.類的聲明:
[attributes] [access-modifiers] class identfier [:[base-class [, inteface(s)]] { class body }
靜態成員和靜態類
靜態成員變數不能預設為public,並且通過類名調用,靜態方法不能使用this reference,不能access非靜態成員變數
靜態類不能執行個體化。 靜態類是密封的(sealed)不能從它派生(derive)類型。 靜態類不能包含非靜態成員也不能有構造方法。
C#部落格第二周