<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Zora Lin on Medium]]></title>
        <description><![CDATA[Stories by Zora Lin on Medium]]></description>
        <link>https://medium.com/@zoralin0725?source=rss-372e67dfadc7------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Azr4RW67U8cBmwhpI-IIjQ.jpeg</url>
            <title>Stories by Zora Lin on Medium</title>
            <link>https://medium.com/@zoralin0725?source=rss-372e67dfadc7------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 16 May 2026 02:20:50 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@zoralin0725/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com" rel="hub"/>
        <item>
            <title><![CDATA[物件導向設計]]></title>
            <link>https://medium.com/@zoralin0725/%E7%89%A9%E4%BB%B6%E5%B0%8E%E5%90%91%E8%A8%AD%E8%A8%88-4cb2c92623b6?source=rss-372e67dfadc7------2</link>
            <guid isPermaLink="false">https://medium.com/p/4cb2c92623b6</guid>
            <dc:creator><![CDATA[Zora Lin]]></dc:creator>
            <pubDate>Mon, 18 Dec 2023 02:04:58 GMT</pubDate>
            <atom:updated>2023-12-19T12:12:47.971Z</atom:updated>
            <content:encoded><![CDATA[<p>我們熟知的物件導向擁有四種特性：<strong>封裝</strong>、<strong>繼承</strong>、<strong>多型</strong>、<strong>抽象。</strong></p><p>這邊不做說明，直接進入我們今日的主題：物件導向設計。<em>Robert C. Martin</em>提出的物件導向設計的五個原則(SOLID)：<strong>單一職責</strong>、<strong>開放封閉</strong>、<strong>里氏替換</strong>、<strong>接口隔離</strong>以及<strong>依賴反轉</strong>。</p><p>SOLID 物件導向設計五原則</p><ol><li><strong>單一職責原則(Single responsibility principle, SRP)</strong></li></ol><blockquote>每個物件，不管是類別、函數，負責的功能，都應該只做一件事。</blockquote><p>對函數而言，一個函數內，同時做了兩件以上的事情。當發生錯誤時，很難快速定位錯誤的原因。另外，也容易間接導至程式碼的可閱讀性降低。簡單來說，就是一個類別應該只有一個職責。</p><p><strong>2. 開放封閉原則(Open-Close principle, OCP)</strong></p><blockquote>藉由<strong>增加新的程式碼</strong>來擴充系統的功能，而不是藉由<strong>修改原本已經存在的程式碼</strong>來擴充系統的功能。</blockquote><p>當需求有異動時，要如何在不變動現在正常運行的程式碼，藉由<strong>繼承</strong>、<strong>相依性注入</strong>等方式，增加新的程式碼，以實作新的需求。</p><p>假若為了新需求，去修改了原本的程式中的某一個函數，可能會造成其他呼叫使用該函數的的功能，出現非預期的錯誤。換句話說，實作完成他應該是「不可修改的」，但是能「擴展」的。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4cb2c92623b6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[C#｜LINQ 延遲執行]]></title>
            <link>https://medium.com/@zoralin0725/c-linq-%E5%BB%B6%E9%81%B2%E5%9F%B7%E8%A1%8C-ee4cbf66d0e0?source=rss-372e67dfadc7------2</link>
            <guid isPermaLink="false">https://medium.com/p/ee4cbf66d0e0</guid>
            <dc:creator><![CDATA[Zora Lin]]></dc:creator>
            <pubDate>Fri, 24 Nov 2023 12:25:39 GMT</pubDate>
            <atom:updated>2023-11-26T03:13:09.203Z</atom:updated>
            <content:encoded><![CDATA[<h3>C#｜LINQ 延遲執行VS立即執行</h3><p>LINQ是一個強大的查詢語言。提供統一的方法對Collection、Array、SQL等來查詢。</p><p>LINQ主要可以分類為兩種方法：延遲執行、立即執行</p><p><strong>延遲執行是什麼?</strong></p><p>意指就是不會馬上執行，查了一下，他又稱作惰性求值(Lazy evaluation)</p><p>我們寫程式，正常不是從上到下，由左到右執行嗎? 一行一行的執行，偏偏延遲執行跟這個運作方式相反。</p><p>延遲執行表示LINQ查詢不會立即執行，而是在實際需要結果的時候才執行。這使得可以構建更複雜的查詢，只有在需要結果的時候才執行計算它們。</p><ol><li>Where</li><li>Select</li><li>OrderBy</li><li>OrderByDescending</li><li>ThenBy</li><li>ThenByDescending</li></ol><p><strong>立即執行是什麼?</strong></p><p>立即執行則是指在調用特定方法時，查詢會立即執行並返回結果。</p><p>1. ToList</p><p>2. ToArray</p><p>3. ToDictionary</p><p>調用以上方法時，因為需循覽才能轉型，會導致LINQ立即執行，將結果直接丟到List, Array, Dictionary中</p><ol><li>Count</li><li>Sum</li><li>Average</li><li>Min</li><li>Max</li></ol><p>調用以上方法時，返回的是一個結果，而不是查詢對象。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ee4cbf66d0e0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[C#｜LINQ筆記]]></title>
            <link>https://medium.com/@zoralin0725/c-linq%E7%AD%86%E8%A8%98-0d3978e83b6b?source=rss-372e67dfadc7------2</link>
            <guid isPermaLink="false">https://medium.com/p/0d3978e83b6b</guid>
            <dc:creator><![CDATA[Zora Lin]]></dc:creator>
            <pubDate>Fri, 24 Nov 2023 09:01:28 GMT</pubDate>
            <atom:updated>2023-11-25T08:19:35.980Z</atom:updated>
            <content:encoded><![CDATA[<ol><li><strong>Any</strong></li></ol><p>用法：檢查Collection是否至少有一個元素符合指定條件</p><p>遇到第一個滿足條件的元素，就會返回True，不再檢查搜索其他元素</p><pre>var nums = new[] { 5, 9, 2, 12, 6 }; <br><br>bool isAnyNumsLargerThan10 = nums.Any(num =&gt; num &gt; 10); <br><br>Console.WriteLine(isAnyNumsLargerThan10); Console.ReadKey();</pre><p>2. All</p><p>用法：判斷每個元素全符合條件</p><pre>var nums = new[] { 5, 9, 2, 12, 6 };<br><br>bool AllIsNumsLargerThanZero = nums.All(num =&gt; num &gt; 0);<br>Console.WriteLine(AllIsNumsLargerThanZero);<br><br>Console.ReadKey();</pre><p>3. Count</p><p>用法：計算Collection中滿足條件的元素有幾個，返回的是int。</p><p>主要有兩種做法：</p><ul><li>計算Collection所有元素的數量</li></ul><pre>List&lt;int&gt; nums = new List&lt;int&gt; { 1, 2, 3, 4, 5 };<br><br>int count = nums.Count();<br><br>Console.WriteLine(count);<br>Console.WriteLine($&quot;集合中的數量有幾個? {count}&quot;);</pre><p>．計算滿足指定條件的元素的數量</p><pre>List&lt;string&gt; words = new List&lt;string&gt; { &quot;apple&quot;, &quot;banana&quot;, &quot;cherry&quot;, &quot;grape&quot; };<br><br>int CountWithSubstring = words.Count(word =&gt; word.Contains(&quot;a&quot;));<br>// Contains用來檢查元素是否存在Collection<br><br>Console.WriteLine($&quot;這個集合包含a字母的數量? : {CountWithSubstring }&quot;);</pre><p>4. LongCount</p><p>跟Count的做法很像，只是他返回的是Long</p><p>Long可以用來容納比int更大的值。</p><pre>List&lt;int&gt; nums = new List&lt;int&gt; { 1, 2, 3, 4, 5 };<br>long countThanThree = nums.LongCount(num =&gt; num &gt; 3)<br><br>Console.WriteLine($&quot;所有大於3的元素數量: {countThanThree}&quot;);</pre><p>5. OrderBy</p><p>用法：對Collection的元素進行排序。(升序)</p><pre>List&lt;int&gt; list = new List&lt;int&gt; { 5, 2, 8, 9, 12 };<br>var sortList = list.OrderBy(x =&gt; x);<br><br>foreach (int x in sortList)<br>{<br>    Console.WriteLine(x);<br>}</pre><p>如果要降序的話，使用 OrderByDescending：</p><pre>var sortListDescending = list.OrderByDescending(x =&gt; x);<br><br>foreach (int x in sortListDescending)<br>{<br>Console.WriteLine(x);<br>}</pre><p>6. ThenBy</p><p>用法：進行二級排序，跟OrderBy一樣用法．</p><pre>List&lt;string&gt; fruits = new List&lt;string&gt; { &quot;Apple&quot;, &quot;Banana&quot;, &quot;Cherry&quot;, &quot;Orange&quot;, &quot;Grape&quot; };<br>// 先按照長度來排序<br>var sortdFruit = fruits.OrderBy(fruit =&gt; fruit.Length)<br>.ThenBy(fruit =&gt; fruit);<br><br>Console.WriteLine(&quot;按照長度和字母順序排序的結果&quot;);<br>foreach (var fruit in sortdFruit)<br>{<br>    Console.WriteLine(fruit);<br>}<br><br>// output:<br>Apple<br>Grape<br>Banana<br>Cherry<br>Orange</pre><p>一樣可以使用降序</p><pre>var sortFruitDescending = fruits.OrderBy(fruit =&gt; fruit.Length)<br>.ThenByDescending(fruit =&gt; fruit);<br>foreach (var fruit in sortFruitDescending)<br>{<br>Console.WriteLine(fruit);<br>}<br><br>// output: <br>Grape<br>Apple<br>Orange<br>Cherry<br>Banana</pre><p>7. First</p><p>用法：返回Collection的第一個元素，如果給予指定詞，將返回match的第一個元素</p><pre>List&lt;int&gt; nums = new List&lt;int&gt; { 17, 8, 9, -1, 2 };<br>var firstNumber = nums.First();<br>Console.WriteLine($&quot;返回的第一個元素? {firstNumber}&quot;);</pre><p>8. Last</p><p>用法：用來返回Collection最後一個元素，如果給予指定詞，將返回match的最後一個元素</p><pre>List&lt;int&gt; nums = new List&lt;int&gt; { 17, 8, 9, -1, 2 };<br>var Lastnums = nums.Last();<br>Console.WriteLine($&quot;返回的最後一個元素 ? {Lastnums}&quot;);</pre><p>First 和 Last 方法在集合為空時會引發異常。如果希望避免這種情況，可以使用 FirstOrDefault 和 LastOrDefault 方法，它們在集合為空時返回預設值</p><p>9. Where</p><p>用法：定義篩選條件，符合條件後，返回一個新的Collection</p><pre>var numbers = new[] { 10, 1, 4, 17, 122 };<br>var evenNumbers = numbers.Where(number =&gt; number % 2 == 0);<br><br>foreach (var number in evenNumbers)<br>{<br>Console.WriteLine($&quot;返回所有偶數 : {number}&quot;);<br>}</pre><p>10. Distinct</p><p>用法：從 Collection中移除所有重複的值</p><pre>var nums = new[] { 10, 1, 10, 4, 17, 17, 122 };<br>var SelectOneDistinct = nums.Distinct();<br>foreach (var item in SelectOneDistinct)<br>{<br>    Console.WriteLine(item);<br>}</pre><p>11. Select</p><p>用法：請參考<a href="https://peterhpchen.github.io/DigDeeperLINQ/09_HowToUseSelect.html#%E6%A0%BC%E5%BC%8F%E8%AA%AA%E6%98%8E">這裡</a>．</p><pre>var nums = new[] { 10, 1, 10, 4, 17, 17, 122 };<br>var SelectNums = nums.Select(num =&gt; num * 2);<br><br>foreach (var num in SelectNums)<br>{<br>    Console.WriteLine(num);<br>}</pre><pre>var animals = new[] { &quot;bear&quot;, &quot;rabbit&quot;, &quot;dog&quot;, &quot;cat&quot; };<br>var UpperCaseAnimals = animals.Select(animals =&gt; animals.ToUpper());<br><br>foreach (var animal in UpperCaseAnimals)<br>{<br>Console.WriteLine(animal);<br>}<br><br>// 加上index<br><br>var animalsIndex = animals.Select((animal, index) =&gt; <br>$&quot;{index + 1}. {animal}&quot;);<br><br>foreach (var animal in animalsIndex)<br>{<br>    Console.WriteLine(animal);<br>}<br><br>// output :<br>1. bear<br>2. rabbit<br>3. dog<br>4. cat</pre><p>12. Average</p><p>用法：計算一組Collection的平均值．</p><p>Average 方法也可以應用於其他數值型別，例如 double 、decimal(小數)，或者對於自訂類型</p><pre>List&lt;int&gt; a = new List&lt;int&gt; { 5, 2, 10, 25, 50 };<br><br>double average = a.Average();<br>Console.WriteLine($&quot;平均值為: {average}&quot;);</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0d3978e83b6b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>