or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Syncing
xxxxxxxxxx
LINQ基礎 - Iterator(疊代器模式)
閒話543
最近開始寫 LinQ 的筆記後才發現 LinQ 與 foreach 在設計模式的實作上 , 原來都有採用 Iterator (疊代器模式) 呀 , 忘記在哪本書裡面看到的 , 它說 : Iterator 由於幾乎被大多數程式語言內化 , 固此模式的學習價值遠高於實戰價值 , Gof 甚至曾經提出要刪除此模式…
定義
我們固然能夠在集合對象中實作走訪的操作 , 但這樣集合對象可能就承擔過多的責任(?). 也就違反設計模式中的單一設計原則(SRP) , 因此我們要盡可能的分離職責 , 讓不同的類別承擔不同的責任. 而 Iterator 模式在 foreach 實作上 , 簡單來說 , 就是將走訪這個動作抽離出來給另一個類別負責.
結構
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →範例 - 走訪整數
例如 : 517 , 會依序走訪 5 然後 1 然後7
.Net 的 Iterator
在 .Net 的 System.Collections 命名空間內 , 早就具有 Iterator 模式的實現 . 也就是 Aggregate 以及 Iterator 這兩個介面的存在.
所以上述範例 - 走訪整數 , 更改下列動作後 , 就可以使用foreach關鍵字.
測試端程式以及輸出結果(我用了foreach)
總結
Thank you!
You can find me on
若有謬誤 , 煩請告知 , 新手發帖請多包涵
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →