13
本本本本本本本本 Vic Chih 2015-11-20

Vic weekly learning_20151120

Embed Size (px)

Citation preview

Page 1: Vic weekly learning_20151120

本週學習心得分享Vic Chih2015-11-20

Page 2: Vic weekly learning_20151120

本週主題• C# MSDN

– Main() and Command-Line Arguments – Properties– Override and new

• 使用 LINQPad– Generics – LINQ

Page 3: Vic weekly learning_20151120

Command-Line Arguments• 透過命令列引數 傳遞參數值給程式• C# command line compiler (csc 來編譯 )• f <int>

Page 4: Vic weekly learning_20151120

Properties (get;set;)• 類似建立 方法 達到設定、取得 private Variable• Set 可以建立篩選規則避免不必要的錯誤• 若把 set 刪除,可以讓 string app 變為唯讀

Page 5: Vic weekly learning_20151120

Override and new• 右邊兩種程式分別實作 new 跟

override• new 的定義是隱藏父類別的 method• Override 的定義是改寫父類別的

method• 但使用 new 的 method 來實作時的結果卻出現 move by : Run• 而 override 的 method 來實作時的結果則出現我們預期的結果 move

by : Swim

Page 6: Vic weekly learning_20151120

Generics Collection• Generics 可以在宣告類別、方法結構時可以引用各種型別• 再搭配 LINQ 使用起來較 array list 更具功能性

Page 7: Vic weekly learning_20151120

LINQ• Language-Integrated Query

– 具備 Query的能力– 目的:透過一致的方法,存取各種資料來源

• Query syntax & Fluent syntax(Lambda Expressions)• LINQ and Deferred Execution

Page 8: Vic weekly learning_20151120

LINQ - Query syntax

Page 9: Vic weekly learning_20151120

LINQ - Fluent syntax

Page 10: Vic weekly learning_20151120

LINQ and Deferred ExecutionLINQ, execution of a query is usually deferred until the moment when you actually request the data

Page 11: Vic weekly learning_20151120

LINQ and Deferred Execution• Deferred execution is a two edged sword:• Composable queries and deferred execution work together to

make LINQ an unusual rich query language. If you properly understand these features of LINQ you will be able to write less code, that executes faster, in order to accomplish more.

• As you have seen, if we don’t properly understand deferred execution then we can end up with a sheepish grin on our face. Queries might not execute when we expect them to, and we might report erroneous results to the user.

Page 13: Vic weekly learning_20151120

Thank you for your listening