<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # =&gt; 運算符(C# 參考) **=&gt;** 標記稱作 lambda 運算符。該標記在 lambda 表達式中用來將左側的輸入變量與右側的 lambda 體分離。Lambda 表達式是與匿名方法類似的內聯表達式,但更加靈活;在以方法語法表示的 LINQ 查詢中廣泛使用了 Lambda 表達式。有關更多信息,請參見[Lambda 表達式(C# 編程指南)](https://msdn.microsoft.com/zh-CN/library/bb397687.aspx)。 下面的示例演示兩種查找并顯示最短的字符串的長度在字符數組中的字符串。該示例的第一部分將 lambda 表達式 (w =&gt; w.Length) words 于數組的每個元素都使用 [Min&lt;TSource&gt;](https://msdn.microsoft.com/zh-CN/library/bb548864.aspx) 方法查找最小長度。為了進行比較,該示例的第二部分演示一個較長的解決方案使用查詢語法執行相同操作。 ``` string[] words = { "cherry", "apple", "blueberry" }; // Use method syntax to apply a lambda expression to each element // of the words array. int shortestWordLength = words.Min(w => w.Length); Console.WriteLine(shortestWordLength); // Compare the following code that uses query syntax. // Get the lengths of each word in the words array. var query = from w in words select w.Length; // Apply the Min method to execute the query and get the shortest length. int shortestWordLength2 = query.Min(); Console.WriteLine(shortestWordLength2); // Output: // 5 // 5 ``` ## 備注 **=&gt;** 運算符具有與賦值運算符 (**=**) 相同的優先級,并且是右結合運算符。 可以顯式指定輸入變量的類型或讓編譯器推斷類型;仍,該變量是強類型在編譯時。當指定類型時,必須將該類型括號中的名稱和變量名,如下例所示。 ``` int shortestWordLength = words.Min((string w) => w.Length); ``` 下面的代碼演示如何編寫采用兩個參數標準查詢運算符 [Enumerable.Where&lt;TSource&gt;](https://msdn.microsoft.com/zh-CN/library/bb549418.aspx) 的超加載的 lambda 表達式。由于 lambda 表達式具有多個參數,必須括在括號中的參數。第二個參數,index,表示當前元素的索引集合中的。 **Where** 表達式返回長度小于其在數組的索引位置小于的任何字符串。 ``` static void Main(string[] args) { string[] digits = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" }; Console.WriteLine("Example that uses a lambda expression:"); var shortDigits = digits.Where((digit, index) => digit.Length < index); foreach (var sD in shortDigits) { Console.WriteLine(sD); } // Compare the following code, which arrives at the same list of short // digits but takes more work to get there. Console.WriteLine("\nExample that uses a for loop:"); List<string> shortDigits2 = new List<string>(); for (var i = 0; i < digits.Length; i++) { if (digits[i].Length < i) shortDigits2.Add(digits[i]); } foreach (var d in shortDigits2) { Console.WriteLine(d); } // Output: // Example that uses a lambda expression: // five // six // seven // eight // nine // Example that uses a for loop: // five // six // seven // eight // nine } ``` ## 請參閱 [C# 參考](https://msdn.microsoft.com/zh-CN/library/618ayhy6.aspx) [C# 編程指南](https://msdn.microsoft.com/zh-CN/library/67ef8sbd.aspx) [Lambda 表達式(C# 編程指南)](https://msdn.microsoft.com/zh-CN/library/bb397687.aspx)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看