久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

      <bdo id='ICULX'></bdo><ul id='ICULX'></ul>
    <tfoot id='ICULX'></tfoot>

      <legend id='ICULX'><style id='ICULX'><dir id='ICULX'><q id='ICULX'></q></dir></style></legend>
      <i id='ICULX'><tr id='ICULX'><dt id='ICULX'><q id='ICULX'><span id='ICULX'><b id='ICULX'><form id='ICULX'><ins id='ICULX'></ins><ul id='ICULX'></ul><sub id='ICULX'></sub></form><legend id='ICULX'></legend><bdo id='ICULX'><pre id='ICULX'><center id='ICULX'></center></pre></bdo></b><th id='ICULX'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='ICULX'><tfoot id='ICULX'></tfoot><dl id='ICULX'><fieldset id='ICULX'></fieldset></dl></div>
      1. <small id='ICULX'></small><noframes id='ICULX'>

        轉換此迭代器塊如何進行功能更改?

        How is transforming this iterator block a functional change?(轉換此迭代器塊如何進行功能更改?)
        • <bdo id='UpgDj'></bdo><ul id='UpgDj'></ul>
          <legend id='UpgDj'><style id='UpgDj'><dir id='UpgDj'><q id='UpgDj'></q></dir></style></legend>
          • <small id='UpgDj'></small><noframes id='UpgDj'>

              <tbody id='UpgDj'></tbody>
              <i id='UpgDj'><tr id='UpgDj'><dt id='UpgDj'><q id='UpgDj'><span id='UpgDj'><b id='UpgDj'><form id='UpgDj'><ins id='UpgDj'></ins><ul id='UpgDj'></ul><sub id='UpgDj'></sub></form><legend id='UpgDj'></legend><bdo id='UpgDj'><pre id='UpgDj'><center id='UpgDj'></center></pre></bdo></b><th id='UpgDj'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='UpgDj'><tfoot id='UpgDj'></tfoot><dl id='UpgDj'><fieldset id='UpgDj'></fieldset></dl></div>
                <tfoot id='UpgDj'></tfoot>

                  本文介紹了轉換此迭代器塊如何進行功能更改?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  給定以下代碼片段:

                  public class Foo
                  {
                      public IEnumerable<string> Sequence { get; set; }
                      public IEnumerable<string> Bar()
                      {
                          foreach (string s in Sequence)
                              yield return s;
                      }
                  }
                  

                  下面的代碼片段在語義上是等價的,還是不同的?如果不同,它們的功能有何不同?

                  is the following snippet semantically equivalent, or is it different? If it is different, how do they function differently?

                  public class Foo2
                  {
                      public IEnumerable<string> Sequence { get; set; }
                      public IEnumerable<string> Bar2()
                      {
                          return Sequence;
                      }
                  }
                  

                  此問題的靈感來自 this question,該問題針對類似情況提出了不同的問題.

                  This question is inspired by this question which is asking a different question about a similar situation.

                  推薦答案

                  兩者不等價.兩個 Bar 方法之間如何延遲執行的語義是不同的.當您調用 Bar 時,Foo.Bar 會將 Sequence 評估為 IEnumerable.當您枚舉 Bar2 返回的序列時,Foo2.Bar2 會將 Sequence 評估為該變量 中的值.

                  The two are not equivalent. The semantics of how execution is deferred between the two Bar methods is different. Foo.Bar will evaluate Sequence into an IEnumerable value when you call Bar. Foo2.Bar2 will evaluate Sequence into the value in that variable when you enumerate the sequence returned by Bar2.

                  我們可以編寫一個足夠簡單的程序來觀察這里的差異.

                  We can write a simple enough program to observe the differences here.

                  //Using iterator block
                  var foo = new Foo();
                  foo.Sequence = new[] { "Old" };
                  var query = foo.Bar();
                  foo.Sequence = new[] { "New" };
                  Console.WriteLine(string.Join(" ", query));
                  
                  //Not using iterator block
                  var foo2 = new Foo2();
                  foo2.Sequence = new[] { "Old" };
                  var query2 = foo2.Bar2();
                  foo2.Sequence = new[] { "New" };
                  Console.WriteLine(string.Join(" ", query2));
                  

                  打印出來:


                  在這種特殊情況下,我們的 Bar 方法也沒有副作用.如果確實如此,那么理解程序具有的語義以及它應該具有的語義就不會變得更加重要.例如,讓我們修改這兩個方法,使其具有一些可觀察到的副作用:

                  In this particular case our Bar method also has no side effects. If it did it would not be noticeably more important to understand the semantics that your program has, and what it should have. For example, let's modify the two methods so that they have some observable side effects:

                  public class Foo
                  {
                      public IEnumerable<string> Sequence { get; set; }
                      public IEnumerable<string> IteratorBlock()
                      {
                          Console.WriteLine("I'm iterating Sequence in an iterator block");
                          foreach (string s in Sequence)
                              yield return s;
                      }
                      public IEnumerable<string> NoIteratorBlock()
                      {
                          Console.WriteLine("I'm iterating Sequence without an iterator block");
                          return Sequence;
                      }
                  }
                  

                  現在讓我們嘗試比較這兩種方法,看看它們是如何工作的:

                  Now let's try comparing these two methods to see how they function:

                  var query = foo.IteratorBlock();
                  var query2 = foo.NoIteratorBlock();
                  Console.WriteLine("---");
                  query.Count();
                  query.Count();
                  query2.Count();
                  query2.Count();
                  

                  這將打印出來:

                  我在沒有迭代器塊的情況下迭代序列
                  ---
                  我正在迭代器塊中迭代序列
                  我正在迭代器塊中迭代序列

                  I'm iterating Sequence without an iterator block
                  ---
                  I'm iterating Sequence in an iterator block
                  I'm iterating Sequence in an iterator block

                  這里我們可以看到非迭代器塊的副作用發生在方法本身被調用時,而迭代器塊的副作用不會在那個時間點發生.然后,稍后,每次我們迭代非迭代器塊時,它根本不會引起副作用,但迭代器塊每次迭代查詢時都會引起副作用.

                  Here we can see that the non-iterator block's side effects happen when the method itself is called, and the iterator block's side effects don't happen at that point in time. Then, later on, each time we iterate the non-iterator block it doesn't cause the side effects at all, but the iterator block causes the side effects each time the query is iterated.

                  這篇關于轉換此迭代器塊如何進行功能更改?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  Ignore whitespace while reading XML(讀取 XML 時忽略空格)
                  XML to LINQ with Checking Null Elements(帶有檢查空元素的 XML 到 LINQ)
                  Reading XML with unclosed tags in C#(在 C# 中讀取帶有未閉合標簽的 XML)
                  Parsing tables, cells with Html agility in C#(在 C# 中使用 Html 敏捷性解析表格、單元格)
                  delete element from xml using LINQ(使用 LINQ 從 xml 中刪除元素)
                  Parse malformed XML(解析格式錯誤的 XML)

                  <tfoot id='BWTO1'></tfoot>

                        <tbody id='BWTO1'></tbody>

                    1. <small id='BWTO1'></small><noframes id='BWTO1'>

                      • <bdo id='BWTO1'></bdo><ul id='BWTO1'></ul>

                        <i id='BWTO1'><tr id='BWTO1'><dt id='BWTO1'><q id='BWTO1'><span id='BWTO1'><b id='BWTO1'><form id='BWTO1'><ins id='BWTO1'></ins><ul id='BWTO1'></ul><sub id='BWTO1'></sub></form><legend id='BWTO1'></legend><bdo id='BWTO1'><pre id='BWTO1'><center id='BWTO1'></center></pre></bdo></b><th id='BWTO1'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='BWTO1'><tfoot id='BWTO1'></tfoot><dl id='BWTO1'><fieldset id='BWTO1'></fieldset></dl></div>
                      • <legend id='BWTO1'><style id='BWTO1'><dir id='BWTO1'><q id='BWTO1'></q></dir></style></legend>

                            主站蜘蛛池模板: 亚洲乱码一区二区三区在线观看 | 国产日韩欧美在线观看 | 免费的av网站 | 久久久久久国产精品免费免费狐狸 | 日韩精品一区二区三区中文字幕 | 99re6在线视频精品免费 | 亚洲视频在线观看 | 九九亚洲精品 | 免费爱爱视频 | 国产精品久久久久久久久久免费 | 亚洲在线免费观看 | 成人在线观看亚洲 | 久久中文字幕一区 | 久久亚洲欧美日韩精品专区 | 国产精品高潮呻吟久久 | 风间由美一区二区三区在线观看 | 日韩精品一区二区三区中文字幕 | 黑人精品欧美一区二区蜜桃 | 一级少妇女片 | 亚洲精品福利视频 | 色嗨嗨 | 国产精品日韩欧美一区二区 | 亚洲国产区 | 日韩欧美一区二区三区免费观看 | 欧美一区二区三区四区视频 | 久久久久精| 一区二区欧美在线 | 亚洲一区日韩 | 国产精品久久久久久久久久久新郎 | 久久久久亚洲精品中文字幕 | 欧美国产精品 | 日韩91| 精品国产91乱码一区二区三区 | 高清国产午夜精品久久久久久 | 在线午夜| 国产一区二区三区四区 | jav成人av免费播放 | 国产精品一区一区 | 欧美区精品 | 亚洲国产精品一区二区第一页 | 欧美亚洲国产一区二区三区 |