DotNet Visual Basic: Yield Keyword in VB.NET 2.0

  • sahilmalikmvp / 206 / Fri, 27 Mar 2009 20:39:00 GMT / Comments (54)
  • What the heck - I can't find it. A bit shocked to see it missing though.

    So "Does VB.NET have the yield keyword, or any equivalent of it" ?
    --

    - Sahil Malik [MVP]
    Upcoming ADO.NET 2.0 book - http://tinyurl.com/9bync
    -----------------------

  • Keywords:

    yield, keyword, vb.net, 2.0, dotnet, visual basic

  • http://dotnet.itags.org/dotnet-visual-basic/163/«« Last Thread - Next Thread »»
    1. Sahil,

      Please to give better posibilities to research and therefore a better
      product, use this newsgroups for Net 2.0 and related products.

      Lab
      http://lab.msdn.microsoft.com/vs2005/community/

      I hope this helps,

      Cor

      corligthert | Wed, 02 Jan 2008 18:22:00 GMT |

    2. Cor,

      I checked that place - no help there.

      I must say, I am incredibly frustrated and very annoyed that something as
      important as the "yield" keyword would be missed out of VB.NET.

      Now try writing a SQLCLR TVF and the 3 lines it takes to accomplish it in C#
      translate to 3 pages of buggy VB.NET code. Highly Highly Highly Highly
      stupid to miss that out IMO.

      - Sahil Malik [MVP]
      Upcoming ADO.NET 2.0 book - http://tinyurl.com/9bync
      -----------------------

      "Cor Ligthert" <notmyfirstname...planet.nl> wrote in message
      news:Owr9F96dFHA.1384...TK2MSFTNGP09.phx.gbl...
      > Sahil,
      > Please to give better posibilities to research and therefore a better
      > product, use this newsgroups for Net 2.0 and related products.
      > Lab
      > http://lab.msdn.microsoft.com/vs2005/community/
      > I hope this helps,
      > Cor

      sahilmalikmvp | Wed, 02 Jan 2008 18:23:00 GMT |

    3. Sahil,

      I think that this reaches where you are looking for. This old Visual Basic
      keyword is probably one of the reasons why what is in C language called
      Static is called in VBNet Shared.

      http://msdn.microsoft.com/library/d...tialization.asp

      I hope this helps,

      Cor

      corligthert | Wed, 02 Jan 2008 18:24:00 GMT |

    4. Cor,

      I'm not talking about "Static/Shared" .. I am talking about "Yield".

      --

      - Sahil Malik [MVP]
      Upcoming ADO.NET 2.0 book - http://tinyurl.com/9bync
      -----------------------

      "Cor Ligthert" <notmyfirstname...planet.nl> wrote in message
      news:uf7uBc7dFHA.1600...tk2msftngp13.phx.gbl...
      > Sahil,
      > I think that this reaches where you are looking for. This old Visual Basic
      > keyword is probably one of the reasons why what is in C language called
      > Static is called in VBNet Shared.
      > http://msdn.microsoft.com/library/d...tialization.asp
      > I hope this helps,
      > Cor

      sahilmalikmvp | Wed, 02 Jan 2008 18:25:00 GMT |

    5. >So "Does VB.NET have the yield keyword, or any equivalent of it" ?

      No. Different languages have different features.

      Mattias

      --
      Mattias Sjgren [MVP] mattias ... mvps.org
      http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
      Please reply only to the newsgroup.

      mattiassjgren | Wed, 02 Jan 2008 18:26:00 GMT |

    6. Thanks Mattias. Finally a direct answer to a simple question.

      - Sahil Malik [MVP]
      Upcoming ADO.NET 2.0 book - http://tinyurl.com/9bync
      -----------------------

      "Mattias Sjgren" <mattias.dont.want.spam...mvps.org> wrote in message
      news:uYJMHQ8dFHA.796...TK2MSFTNGP09.phx.gbl...
      > >So "Does VB.NET have the yield keyword, or any equivalent of it" ?
      > No. Different languages have different features.
      >
      > Mattias
      > --
      > Mattias Sjgren [MVP] mattias ... mvps.org
      > http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
      > Please reply only to the newsgroup.

      sahilmalikmvp | Wed, 02 Jan 2008 18:27:00 GMT |

    7. Sahil,

      > I'm not talking about "Static/Shared" .. I am talking about "Yield".
      I assume that you do not know what Static is in VBNet, therefore I gave you
      the link to the page.

      If you want a mercedes with a chevrolet logo, than you have to put that logo
      on it yourself, Mercedes does not do that for you.

      However I find the Mercedes logo is not bad at all

      static d as integer
      For each a in b
      d += 1
      Next

      This gives you at the end of your program the total result of loops or if
      you set it conditional to zero let you go on where you was in the loop.

      I am not busy with 2005, however short reading gave me the idea that this
      was the idea.

      I hope this helps,

      Cor

      corligthert | Wed, 02 Jan 2008 18:28:00 GMT |

    8. Cor Ligthert wrote:

      > Sahil,
      > > I'm not talking about "Static/Shared" .. I am talking about "Yield".
      > I assume that you do not know what Static is in VBNet, therefore I
      > gave you the link to the page.
      > If you want a mercedes with a chevrolet logo, than you have to put
      > that logo on it yourself, Mercedes does not do that for you.
      > However I find the Mercedes logo is not bad at all
      > static d as integer
      > For each a in b
      > d += 1
      > Next
      > This gives you at the end of your program the total result of loops
      > or if you set it conditional to zero let you go on where you was in
      > the loop.
      > I am not busy with 2005, however short reading gave me the idea that
      > this was the idea.

      yield is a keyword which is only valid in custom enumerator routines
      ('iterators'), something which is C# 2.0 only if I'm not mistaken. It's
      therefore logical VB.NET doesn't have a yield equivalent, as it doesn't
      support custom iterator creation (though it's my understanding it does
      support consuming them). At least, that's my understanding, but I might
      have overlooked something.

      Therefore, babbling about static/shared is erm... completely
      irrelevant ;)

      FB

      --
      ----------------------
      Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
      My .NET blog: http://weblogs.asp.net/fbouma
      Microsoft MVP (C#)
      ----------------------

      fransboumacmvp | Wed, 02 Jan 2008 18:29:00 GMT |

    9. Sahil Malik [MVP] wrote:

      > What the heck - I can't find it. A bit shocked to see it missing
      > though.
      > So "Does VB.NET have the yield keyword, or any equivalent of it" ?

      yield is a keyword for custom iterators, which IMHO is something
      which is C# only.

      However, it's not hard to work around it. After all, we all write code
      today which works OK right? :)

      FB

      --
      ----------------------
      Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
      My .NET blog: http://weblogs.asp.net/fbouma
      Microsoft MVP (C#)
      ----------------------

      fransboumacmvp | Wed, 02 Jan 2008 18:30:00 GMT |

    10. Frans,

      > Therefore, babbling about static/shared is erm... completely
      > irrelevant ;)
      Do you know what the static keyword means in VBNet? (This message is
      crossposted sent to the language.vb newsgroup).

      It has nothing (slightly because it is Static) to do with shared, as I told
      in my first reply. What I only told to keep out confusing from C biased
      persons. However .................:-(

      I have as well not said it is the same,

      Although this text on MSDN gives me the idea that it is a static object.

      Using the new yield keyword, your program can return values back to the
      foreach statement that called the iterator. The next time the foreach
      statement loops and calls the iterator again, the iterator begins its
      execution where the previous yield statement left off

      Cor

      corligthert | Wed, 02 Jan 2008 18:31:00 GMT |

    11. Frans,

      Maybe I show it with a sample what my idea was that yield does and why there
      is no need for it in VBNet because there is the static keyword.

      \\\
      Private Sub Whatever
      Dim myarray() As String = {"1", "2", "3", "4"}
      myproc(myarray, "First")
      myproc(myarray, "Second")
      End Sub
      Private Sub myproc(ByVal myarray() As String, _
      ByVal fase As String)
      Static i As Integer
      For i = i To myarray.Length
      Dim y As Integer
      If y = 2 Then Exit For
      y += 1
      Console.Write(i.ToString & " " & fase & vbCrLf)
      Next
      End Sub
      ///

      Cor

      corligthert | Wed, 02 Jan 2008 18:32:00 GMT |

    12. You will always see simple errors in quick made code.

      It thought it did work however that is strange, it has to be
      \\\
      Private Sub Whatever
      Dim myarray() As String = {"1", "2", "3", "4"}
      myproc(myarray, "First")
      myproc(myarray, "Second")
      End Sub
      Private Sub myproc(ByVal myarray() As String, _
      ByVal fase As String)
      Static i As Integer
      Dim y As Integer
      For i = i To myarray.Length
      If y = 2 Then Exit For
      y += 1
      Console.Write(i.ToString & " " & fase & vbCrLf)
      Next
      End Sub
      ///

      corligthert | Wed, 02 Jan 2008 18:33:00 GMT |

    13. As Frans mentions, Custom iterators are not supported in VB.NET. So it does
      not have/need an yield equivalent.

      --
      Rgds,
      Anand
      VB.NET MVP
      http://www.dotnetindia.com

      "Sahil Malik [MVP]" wrote:

      > What the heck - I can't find it. A bit shocked to see it missing though.
      > So "Does VB.NET have the yield keyword, or any equivalent of it" ?
      > --
      > - Sahil Malik [MVP]
      > Upcoming ADO.NET 2.0 book - http://tinyurl.com/9bync
      > -----------------------
      >

      anandmvp | Wed, 02 Jan 2008 18:34:00 GMT |

    14. "Cor Ligthert" <notmyfirstname...planet.nl> schrieb:
      > Maybe I show it with a sample what my idea was that yield does and why
      > there is no need for it in VBNet because there is the static keyword.
      > \\\
      > Private Sub Whatever
      > Dim myarray() As String = {"1", "2", "3", "4"}
      > myproc(myarray, "First")
      > myproc(myarray, "Second")
      > End Sub
      > Private Sub myproc(ByVal myarray() As String, _
      > ByVal fase As String)
      > Static i As Integer
      > For i = i To myarray.Length
      > Dim y As Integer
      > If y = 2 Then Exit For
      > y += 1
      > Console.Write(i.ToString & " " & fase & vbCrLf)
      > Next
      > End Sub
      > ///

      This samples doesn't show how to workaround the missing 'yield' keyword in
      VB. The sample below is taken from the Beta documentation of Whidbey (C#):

      \\\
      public class List
      {
      public static IEnumerable Power(int number, int exponent)
      {
      int counter = 0;
      int result = 1;
      while(counter++ < exponent)
      {
      result = result * number;
      yield return result;
      }
      }

      static void Main()
      {
      // Display powers of 2 up to the exponent 8:
      foreach(int i in Power(2, 8))
      Console.Write("{0} ", i);
      }
      }
      ///

      --
      M S Herfried K. Wagner
      M V P <URL:http://dotnet.mvps.org/>
      V B <URL:http://classicvb.org/petition/

      herfriedkwagnermvp | Wed, 02 Jan 2008 18:35:00 GMT |

    15. Herfried,

      I have used this from MSDN.

      In the following example, the foreach loop that calls this iterator will
      execute three times, each time receiving the strings in the order specified
      by the previous three yield statements:
      List list = new List();
      foreach(string s in list)
      {
      Console.WriteLine(s);
      }
      If you want the program to implement the iterator to traverse the elements
      in the list, you would modify the iterator to step across the array of
      elements using a foreach loop, yielding each item in the array in every
      iteration:

      public class List
      {
      internal object[] elements;
      internal int count;

      public object foreach()
      {
      foreach(object o in elements)
      {
      yield o;
      }
      }
      }
      However it is not worth the discussion.

      It was more that some people where suggesting that static in VBNet is the
      same as in C#.

      It seems for me that they don't know this VBNet 2003 keyword that has no
      equivalent in C# and it seems still in not.

      Cor

      corligthert | Wed, 02 Jan 2008 18:36:00 GMT |

    16. Cor Ligthert wrote:

      > Frans,
      > > Therefore, babbling about static/shared is erm... completely
      > > irrelevant ;)
      > Do you know what the static keyword means in VBNet? (This message is
      > crossposted sent to the language.vb newsgroup).

      Is this a popquiz? No I don't know what 'Static' means in VB.NET, I
      don't use VB.NET. But I've looked it up, and it seems similar to
      'static' in C if you define a static var in a C-routine. I also fail to
      see what the particular relevance of 'Static vars' are in a method, as
      they can lead to very unpredictable code, and IF you need to preserve
      per-method call values for local vars, I can only think of 1 situation:
      recursion. Now, you can better use the stack for that, don't you think?
      :)

      > It has nothing (slightly because it is Static) to do with shared, as
      > I told in my first reply. What I only told to keep out confusing from
      > C biased persons. However .................:-(

      Great, but what's the relevance to yield ?

      > I have as well not said it is the same,
      > Although this text on MSDN gives me the idea that it is a static
      > object.
      > Using the new yield keyword, your program can return values back to
      > the foreach statement that called the iterator. The next time the
      > foreach statement loops and calls the iterator again, the iterator
      > begins its execution where the previous yield statement left off

      No, it would be a method using object-level static values, and thus
      use 'shared' elements, not 'static' elements.

      FB

      --
      ----------------------
      Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
      My .NET blog: http://weblogs.asp.net/fbouma
      Microsoft MVP (C#)
      ----------------------

      fransboumacmvp | Wed, 02 Jan 2008 18:37:00 GMT |

    17. Cor Ligthert wrote:

      > You will always see simple errors in quick made code.
      > It thought it did work however that is strange, it has to be
      > \\\
      > Private Sub Whatever
      > Dim myarray() As String = {"1", "2", "3", "4"}
      > myproc(myarray, "First")
      > myproc(myarray, "Second")
      > End Sub
      > Private Sub myproc(ByVal myarray() As String, _
      > ByVal fase As String)
      > Static i As Integer
      > Dim y As Integer
      > For i = i To myarray.Length
      > If y = 2 Then Exit For
      > y += 1
      > Console.Write(i.ToString & " " & fase & vbCrLf)
      > Next
      > End Sub
      > ///

      What are you trying to do in this routine? The second call to myproc i
      will be myarray.Length so the loop fails. The static keyword keeps the
      value of 'i'. Though take a step back and look at the code you wrote.
      No-one will use this kind of code in production software, because there
      are far better ways to accomplish the same thing, which ARE more
      readable as you can determine what a variable's contents is when the
      routine is started (i.e. deterministic code, vs. your non-deterministic
      code).

      You could mimic an iterator using a wrapper class, and which calls a
      delegate on each iteration (to make it generic). Though to set this up
      is not transparent, i.e.: it requires work, something which is
      transparent for the user of a .NET 2.0 iterator: just iterate over the
      structure, whatever the structure represents.

      Iterators are just to make foreach loops possible. So you can for
      example foreach over a linked list, now that's a bit problematic, (not
      undoable). Though there is always a way to do it differently, for
      example by using the structures characteristics, in my example of the
      linked list, you could use a While Not node.Next Is Nothing (C#:
      while(node.Next!=null) {} ). That won't change in .NET 2.0. With
      iterators, you just can create another way to iterate over a structure,
      one which is usable in foreach. So if you step away from 'I want to use
      foreach' and look at the code and just implement what gets the job
      done, you will see iterators aren't a requirement, but a convenience
      (and a convenience to the user if I'd might add ;))

      FB

      --
      ----------------------
      Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
      My .NET blog: http://weblogs.asp.net/fbouma
      Microsoft MVP (C#)
      ----------------------

      fransboumacmvp | Wed, 02 Jan 2008 18:38:00 GMT |

    18. Frans,

      Have a nice day, maybe it is better that you walk to the end of the 'pier'
      take a deep breath and ask yourself: "Is this the tone I have to write in a
      newsgroup".

      Cor

      corligthert | Wed, 02 Jan 2008 18:39:00 GMT |

    19. > What are you trying to do in this routine? The second call to myproc i
      > will be myarray.Length so the loop fails.

      It runs, you did obvious not try it, it gives as result
      0 first
      1 first
      2 second
      3 second

      >Though take a step back and look at the code you wrote.
      > No-one will use this kind of code in production software, because there
      > are far better ways to accomplish the same thing,

      Did I say that, I don't like the static keyword. It is to much hidden. That
      is one of the things that Jon Skeet and I very much agree about.

      By the way, based on the view things that I now have read about the 'yield',
      have I on first sights the idea about that last as well.

      For the rest of your message I don't see the sense therefore I keep it with
      this.

      Cor

      corligthert | Wed, 02 Jan 2008 18:40:00 GMT |

    20. "Cor Ligthert" <notmyfirstname...planet.nl> schrieb:
      >> What are you trying to do in this routine? The second call to myproc i
      >> will be myarray.Length so the loop fails.
      > It runs, you did obvious not try it, it gives as result
      > 0 first
      > 1 first
      > 2 second
      > 3 second

      Yeah, but it has nothing to do with iterators ;-).

      --
      M S Herfried K. Wagner
      M V P <URL:http://dotnet.mvps.org/>
      V B <URL:http://classicvb.org/petition/>

      herfriedkwagnermvp | Wed, 02 Jan 2008 18:41:00 GMT |

    21. Cor Ligthert wrote:

      > Frans,
      > Have a nice day, maybe it is better that you walk to the end of the
      > 'pier' take a deep breath and ask yourself: "Is this the tone I have
      > to write in a newsgroup".

      err, what's the problem? I just pointed out that what you tried to
      explain is something completely different than yield.

      Besides that, it's way too hot on the beach now.

      FB

      --
      ----------------------
      Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
      My .NET blog: http://weblogs.asp.net/fbouma
      Microsoft MVP (C#)
      ----------------------

      fransboumacmvp | Wed, 02 Jan 2008 18:42:00 GMT |

    22. Cor Ligthert wrote:

      > > What are you trying to do in this routine? The second call to
      > > myproc i will be myarray.Length so the loop fails.
      > It runs, you did obvious not try it, it gives as result
      > 0 first
      > 1 first
      > 2 second
      > 3 second

      oh due to the if y=2 then break blah. OK, overlooked that one, in my
      blindness caused by the Static keyword. I didn't try the code.

      I fail to see what it has to illustrate though.

      > > Though take a step back and look at the code you wrote.
      > > No-one will use this kind of code in production software, because
      > > there are far better ways to accomplish the same thing,
      > Did I say that, I don't like the static keyword. It is to much
      > hidden. That is one of the things that Jon Skeet and I very much
      > agree about.

      I just wanted to explain that code like you wrote is hard to read,
      thus not what you want. This was mainly caused by the static keyword.
      I.o.w.: static is IMHO a keyword you should better avoid (like goto),
      and thus IF iterators would be programmable using static, like you
      suggested, it wouldn't be a big win, on the contrary, you'd better opt
      for a different approach.

      FB

      --
      ----------------------
      Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
      My .NET blog: http://weblogs.asp.net/fbouma
      Microsoft MVP (C#)
      ----------------------

      fransboumacmvp | Wed, 02 Jan 2008 18:43:00 GMT |

    23. Herfried,

      I only tried to give Sahil an alternative for his 'yield'.

      The static is the one that comes in my idea the most near at it.

      And than I got reply that was in my opinion about a shared class and his
      members.

      I am quiet sure that the yield is not exactly the same as a VB static,
      otherwise I had given an example with a foreach.

      Although in my idea is it not imposible that it will act internal not much
      less than a VB static variable. You cannot keep values in memory and in the
      same time let them go out of scope.

      However that I cannot oversee, and was as well not the meaning of my answer.

      Cor

      corligthert | Wed, 02 Jan 2008 18:44:00 GMT |

    24. Cor,

      What the hell are you talking about? Anyway, I got my answer from Mattias.

      - Sahil Malik [MVP]
      Upcoming ADO.NET 2.0 book - http://tinyurl.com/9bync
      -----------------------

      "Cor Ligthert" <notmyfirstname...planet.nl> wrote in message
      news:eUp$qU8dFHA.3376...TK2MSFTNGP10.phx.gbl...
      > Sahil,
      >> I'm not talking about "Static/Shared" .. I am talking about "Yield".
      >>
      > I assume that you do not know what Static is in VBNet, therefore I gave
      > you the link to the page.
      > If you want a mercedes with a chevrolet logo, than you have to put that
      > logo on it yourself, Mercedes does not do that for you.
      > However I find the Mercedes logo is not bad at all
      > static d as integer
      > For each a in b
      > d += 1
      > Next
      > This gives you at the end of your program the total result of loops or if
      > you set it conditional to zero let you go on where you was in the loop.
      > I am not busy with 2005, however short reading gave me the idea that this
      > was the idea.
      > I hope this helps,
      > Cor

      sahilmalikmvp | Wed, 02 Jan 2008 18:45:00 GMT |

    25. Cor,

      Frans is completely right in this regard. I asked you about yield, you are
      telling me about static/shared - seriously are you just trying to get your
      post count up?

      - Sahil Malik [MVP]
      Upcoming ADO.NET 2.0 book - http://tinyurl.com/9bync
      -----------------------

      "Cor Ligthert" <notmyfirstname...planet.nl> wrote in message
      news:epm6aW%23dFHA.4040...TK2MSFTNGP14.phx.gbl...
      > Frans,
      > Have a nice day, maybe it is better that you walk to the end of the 'pier'
      > take a deep breath and ask yourself: "Is this the tone I have to write in
      > a newsgroup".
      > Cor

      sahilmalikmvp | Wed, 02 Jan 2008 18:46:00 GMT |

    26. > Yeah, but it has nothing to do with iterators ;-).

      E-X-A-C-T-L-Y MY POINT :-)

      - Sahil Malik [MVP]
      Upcoming ADO.NET 2.0 book - http://tinyurl.com/9bync
      -----------------------

      "Herfried K. Wagner [MVP]" <hirf-spam-me-here...gmx.at> wrote in message
      news:ebQBl5%23dFHA.2288...TK2MSFTNGP14.phx.gbl...
      > "Cor Ligthert" <notmyfirstname...planet.nl> schrieb:
      >>> What are you trying to do in this routine? The second call to myproc i
      >>> will be myarray.Length so the loop fails.
      >>
      >> It runs, you did obvious not try it, it gives as result
      >> 0 first
      >> 1 first
      >> 2 second
      >> 3 second
      > Yeah, but it has nothing to do with iterators ;-).
      > --
      > M S Herfried K. Wagner
      > M V P <URL:http://dotnet.mvps.org/>
      > V B <URL:http://classicvb.org/petition/

      sahilmalikmvp | Wed, 02 Jan 2008 18:47:00 GMT |

    27. Well I did write up an enumerator class myself. It's not a super big deal,
      but just annoying that something I could have done in 3 lines of code in VB
      requires me to implement another class. Anyway, that is something what is
      done behind the scenes by yield anyway - and I beleive it is threadsafe
      code, so yield isn't too shabby IMO.

      - Sahil Malik [MVP]
      Upcoming ADO.NET 2.0 book - http://tinyurl.com/9bync
      -----------------------

      "Frans Bouma [C# MVP]" <perseus.usenetNOSPAM...xs4all.nl> wrote in message
      news:xn0e3u6ts6dgtl002...news.microsoft.com...
      > Sahil Malik [MVP] wrote:
      >> What the heck - I can't find it. A bit shocked to see it missing
      >> though.
      >>
      >> So "Does VB.NET have the yield keyword, or any equivalent of it" ?
      > yield is a keyword for custom iterators, which IMHO is something
      > which is C# only.
      > However, it's not hard to work around it. After all, we all write code
      > today which works OK right? :)
      > FB
      > --
      > ----------------------
      > Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
      > My .NET blog: http://weblogs.asp.net/fbouma
      > Microsoft MVP (C#)
      > ----------------------

      sahilmalikmvp | Wed, 02 Jan 2008 18:48:00 GMT |

    28. Sahil,

      > Frans is completely right in this regard. I asked you about yield, you are
      > telling me about static/shared -

      Maybe it is wise that you buy this book before you go on in that one that
      you are endless telling in these newsgroup that you are writting now.

      http://www.nbcindia.com/Descriptions.asp?title_id=2545

      I hope this helps,

      Cor

      corligthert | Wed, 02 Jan 2008 18:49:00 GMT |

    29. > or any equivalent of it" ?

      "Sahil Malik [MVP]" <contactmethrumyblog...nospam.com> schreef in bericht
      news:urcc2U$dFHA.1600...tk2msftngp13.phx.gbl...
      >> Yeah, but it has nothing to do with iterators ;-).
      > E-X-A-C-T-L-Y MY POINT :-)
      > Upcoming ADO.NET 2.0 book - http://tinyurl.com/9bync
      > What the heck - I can't find it. A bit shocked to see it missing though.
      > or any equivalent of it" ?
      > --
      > - Sahil Malik [MVP]
      > Upcoming ADO.NET 2.0 book - http://tinyurl.com/9bync
      > -----------------------

      corligthert | Wed, 02 Jan 2008 18:50:00 GMT |

    30. Cor,

      "Cor Ligthert" <notmyfirstname...planet.nl> schrieb:
      > I only tried to give Sahil an alternative for his 'yield'.

      As I say, your sample is /not/ an alternative.

      > The static is the one that comes in my idea the most near at it.

      It doesn't. Take a look at the C# sample I posted in the other reply.

      > And than I got reply that was in my opinion about a shared class and his
      > members.
      > I am quiet sure that the yield is not exactly the same as a VB static,
      > otherwise I had given an example with a foreach.
      > Although in my idea is it not imposible that it will act internal not much
      > less than a VB static variable. You cannot keep values in memory and in
      > the same time let them go out of scope.

      Static variables in VB.NET won't help much. The trick behind the 'yield' is
      that it returns the value to the iterator but doesn't exit the method. This
      behavior can be faked using delegates, as mentioned in another reply.

      --
      M S Herfried K. Wagner
      M V P <URL:http://dotnet.mvps.org/>
      V B <URL:http://classicvb.org/petition/

      herfriedkwagnermvp | Wed, 02 Jan 2008 18:51:00 GMT |

    31. "Frans Bouma [C# MVP]" <perseus.usenetNOSPAM...xs4all.nl> schrieb:
      > I just wanted to explain that code like you wrote is hard to read,
      > thus not what you want. This was mainly caused by the static keyword.
      > I.o.w.: static is IMHO a keyword you should better avoid (like goto),

      I disagree. There are certain cases where 'Static' makes perfect sense and
      additionally leads to better-encapsulated code than using a private (shared)
      field. Note that this should not encourage the use of 'Static' where it
      doesn't make much sense ;-).

      --
      M S Herfried K. Wagner
      M V P <URL:http://dotnet.mvps.org/>
      V B <URL:http://classicvb.org/petition/

      herfriedkwagnermvp | Wed, 02 Jan 2008 18:52:00 GMT |

    32. "Cor Ligthert" <notmyfirstname...planet.nl> schrieb:
      >> Frans is completely right in this regard. I asked you about yield, you
      >> are telling me about static/shared -
      > Maybe it is wise that you buy this book before you go on in that one that
      > you are endless telling in these newsgroup that you are writting now.
      > http://www.nbcindia.com/Descriptions.asp?title_id=2545

      Cor, try to keep it outside the groups.

      "A real man can admit when he makes a mistake."

      --
      M S Herfried K. Wagner
      M V P <URL:http://dotnet.mvps.org/>
      V B <URL:http://classicvb.org/petition/

      herfriedkwagnermvp | Wed, 02 Jan 2008 18:53:00 GMT |

    33. Maybe a feeble attempt at humor will ligthen things up. My buddy Roland
      once gave me this expression and I loved it becuase, well, it's practically
      my personal motto "
      Doe maar gewoon, dan doe je al gek genoeg"

      http://rolandboon.net/WSBeanRSS/Web...ay=2004-12-30/1

      This is probably a good time for us all to listen to good old Roland ;-)

      Also , remind me to tell you about our discussion after the user's group
      about business objects.
      --
      W.G. Ryan, MVP

      www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
      "Sahil Malik [MVP]" <contactmethrumyblog...nospam.com> wrote in message
      news:%23BJU5d5dFHA.2288...TK2MSFTNGP14.phx.gbl...
      > What the heck - I can't find it. A bit shocked to see it missing though.
      > So "Does VB.NET have the yield keyword, or any equivalent of it" ?
      > --
      > - Sahil Malik [MVP]
      > Upcoming ADO.NET 2.0 book - http://tinyurl.com/9bync
      > -----------------------

      w_g_ryanemvp | Wed, 02 Jan 2008 18:54:00 GMT |

    34. Herfried,

      As I said, I have to little information about the yield. I gave my answer as
      a maybe equivalent of it.

      Where I wrote "I think that this reaches where you are looking for".

      The answer on this message was
      \\\
      I'm not talking about "Static/Shared" .. I am talking about "Yield".
      ///

      This answer could have been as well in a decent way, however it gave me the
      idea that the OP did/does (still) not know what static means VB as special
      keyword inside a procedure. Therefore I tried to explain it by samples.

      You always learns in these newsgroup.

      :-))

      Cor

      corligthert | Wed, 02 Jan 2008 18:55:00 GMT |

    35. Herfried,

      > Cor, try to keep it outside the groups.
      As you know I try forever, however sometimes I get angry when the mud is to
      much.
      However you are right in this one.

      If you look at the last replies from Frans than you see what I tried to
      tell.
      (The one you have replied now that you disagreed. And do that than because
      of that as well with me).

      > "A real man can admit when he makes a mistake."
      I am not mistaking in this. In my opinion have I nowhere written what you
      probably think that you read from the answers from others.

      See my other message to your thread written before I could read this one.

      Cor

      corligthert | Wed, 02 Jan 2008 18:56:00 GMT |

    36. Bill,

      > Doe maar gewoon, dan doe je al gek genoeg"
      I have the idea, if Frans tell that I am not than I will agree.

      Dit slaat als een tang op een varken.

      :-)))

      Cor

      corligthert | Wed, 02 Jan 2008 18:57:00 GMT |

    37. Herfried K. Wagner [MVP] wrote:

      > "Frans Bouma [C# MVP]" <perseus.usenetNOSPAM...xs4all.nl> schrieb:
      > > I just wanted to explain that code like you wrote is hard to read,
      > > thus not what you want. This was mainly caused by the static
      > > keyword. I.o.w.: static is IMHO a keyword you should better avoid
      > > (like goto),
      > I disagree. There are certain cases where 'Static' makes perfect
      > sense and additionally leads to better-encapsulated code than using a
      > private (shared) field. Note that this should not encourage the use
      > of 'Static' where it doesn't make much sense ;-).

      Now I'm interested in what these situations are. Could you give an
      explanation where it will give much BETTER code than when you wouldn't
      have the Static keyword?

      FB

      --
      ----------------------
      Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
      My .NET blog: http://weblogs.asp.net/fbouma
      Microsoft MVP (C#)
      ----------------------

      fransboumacmvp | Wed, 02 Jan 2008 18:58:00 GMT |

    38. I actually got that phrase from Rolan Boon. I have a LONG way to go
      learning Dutch before I make it over there at the end of the year.

      Mijn Nederlands is slecht, maar ik denk ik begrijp
      What I was hoping to say is that My dutch isn't all that good, but I think I
      understood your point.
      --
      W.G. Ryan, MVP

      www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
      "Cor Ligthert" <notmyfirstname...planet.nl> wrote in message
      news:%23T5tr4$dFHA.412...tk2msftngp13.phx.gbl...
      > Bill,
      >> Doe maar gewoon, dan doe je al gek genoeg"
      >>
      > I have the idea, if Frans tell that I am not than I will agree.
      > Dit slaat als een tang op een varken.
      > :-)))
      > Cor

      w_g_ryanemvp | Wed, 02 Jan 2008 18:59:00 GMT |

    39. Cor Ligthert wrote:

      > Bill,
      > > Doe maar gewoon, dan doe je al gek genoeg"
      > I have the idea, if Frans tell that I am not than I will agree.

      wat is dit voor steenkolen-engels, man :)

      > Dit slaat als een tang op een varken.

      indeed :)

      FB

      fransboumacmvp | Wed, 02 Jan 2008 19:00:00 GMT |

    40. > "A real man can admit when he makes a mistake."

      Cor should "yield" when he is being "static" ? LOL

      - Sahil Malik [MVP]
      Upcoming ADO.NET 2.0 book - http://tinyurl.com/9bync
      -----------------------
      -----

      "Herfried K. Wagner [MVP]" <hirf-spam-me-here...gmx.at> wrote in message
      news:ufXwFr$dFHA.220...TK2MSFTNGP12.phx.gbl...
      > "Cor Ligthert" <notmyfirstname...planet.nl> schrieb:
      > >> Frans is completely right in this regard. I asked you about yield, you
      > >> are telling me about static/shared -
      > > Maybe it is wise that you buy this book before you go on in that one
      that
      > > you are endless telling in these newsgroup that you are writting now.
      > > http://www.nbcindia.com/Descriptions.asp?title_id=2545
      > Cor, try to keep it outside the groups.
      > "A real man can admit when he makes a mistake."
      > --
      > M S Herfried K. Wagner
      > M V P <URL:http://dotnet.mvps.org/>
      > V B <URL:http://classicvb.org/petition/

      sahilmalikmvp | Wed, 02 Jan 2008 19:01:00 GMT |

    41. "Frans Bouma [C# MVP]" <

      >>> I have the idea, if Frans tell that I am not than I will agree.
      > wat is dit voor steenkolen-engels, man :)

      Indeed :-)

      Cor

      corligthert | Wed, 02 Jan 2008 19:02:00 GMT |

    42. Bill,
      > Mijn Nederlands is slecht, maar ik denk dat ik het begrijp

      If it is not Bablefish than it was very good.

      The English meaning of

      Het slaat als een tang op een varken

      That fits as a flag on a broomstick

      :-)

      Cor

      corligthert | Wed, 02 Jan 2008 19:03:00 GMT |

    43. Static is not an equivalent of Yield.

      - Sahil Malik [MVP]
      Upcoming ADO.NET 2.0 book - http://tinyurl.com/9bync
      -----------------------

      "Cor Ligthert" <notmyfirstname...planet.nl> wrote in message
      news:OnxxFm$dFHA.3864...TK2MSFTNGP10.phx.gbl...
      >> or any equivalent of it" ?
      > "Sahil Malik [MVP]" <contactmethrumyblog...nospam.com> schreef in bericht
      > news:urcc2U$dFHA.1600...tk2msftngp13.phx.gbl...
      >>> Yeah, but it has nothing to do with iterators ;-).
      >>
      >> E-X-A-C-T-L-Y MY POINT :-)
      >>
      >> Upcoming ADO.NET 2.0 book - http://tinyurl.com/9bync
      >> What the heck - I can't find it. A bit shocked to see it missing though.
      >>
      >> or any equivalent of it" ?
      >> --
      >>
      >> - Sahil Malik [MVP]
      >> Upcoming ADO.NET 2.0 book - http://tinyurl.com/9bync
      >> -----------------------
      >>

      sahilmalikmvp | Wed, 02 Jan 2008 19:04:00 GMT |

    44. Cor,

      Lets try one more time now -

      "I asked about "Yield" and you told me about Static."

      Get it?

      - Sahil Malik [MVP]
      Upcoming ADO.NET 2.0 book - http://tinyurl.com/9bync
      -----------------------

      "Cor Ligthert" <notmyfirstname...planet.nl> wrote in message
      news:ecHCHg$dFHA.3492...TK2MSFTNGP14.phx.gbl...
      > Sahil,
      >> Frans is completely right in this regard. I asked you about yield, you
      >> are telling me about static/shared -
      > Maybe it is wise that you buy this book before you go on in that one that
      > you are endless telling in these newsgroup that you are writting now.
      > http://www.nbcindia.com/Descriptions.asp?title_id=2545
      > I hope this helps,
      > Cor

      sahilmalikmvp | Wed, 02 Jan 2008 19:05:00 GMT |

    45. "Frans Bouma [C# MVP]" <perseus.usenetNOSPAM...xs4all.nl> schrieb:
      >> > I just wanted to explain that code like you wrote is hard to read,
      >> > thus not what you want. This was mainly caused by the static
      >> > keyword. I.o.w.: static is IMHO a keyword you should better avoid
      >> > (like goto),
      >>
      >> I disagree. There are certain cases where 'Static' makes perfect
      >> sense and additionally leads to better-encapsulated code than using a
      >> private (shared) field. Note that this should not encourage the use
      >> of 'Static' where it doesn't make much sense ;-).
      > Now I'm interested in what these situations are. Could you give an
      > explanation where it will give much BETTER code than when you wouldn't
      > have the Static keyword?

      I never said that it will give /much/ better code! One of the Windows Forms
      FAQs is how to execute certain code only the first time a Windows Forms form
      is activated. There are many different solutions to the problem which have
      different advantages and disadvantages. Sure, you could create a private
      field instead of the static variable below, but I think that a static
      variable encapsulates the whole functionality more tightly:

      \\\
      Private Sub Form1_Activated( _
      ByVal sender As Object, _
      ByVal e As EventArgs _
      ) Handles MyBase.Activated
      Static IsActivated As Boolean
      If Not IsActivated Then
      IsActivated = True
      Application.DoEvents() ' ...
      MsgBox("Form activated for the first time!")
      End If
      End Sub
      ///

      Today's code often suffers from the problem that private variables holding
      values used in a method or property semantically belong to a certain method
      or property, and /not/ to the whole class. For methods this problem can be
      reduced by using static variables. Similar functionality for properties
      would be great, for example, something like the code below:

      \\\
      Public Property TheFoo() As Foo
      Dim TheFooValue As Foo
      Get
      Return TheFooValue
      End Get
      Set(ByVal Value As Foo)
      TheFooValue = Value
      End Set
      End Property
      ///

      However, this is currently not supported.

      --
      M S Herfried K. Wagner
      M V P <URL:http://dotnet.mvps.org/>
      V B <URL:http://classicvb.org/petition/

      herfriedkwagnermvp | Wed, 02 Jan 2008 19:06:00 GMT |

    46. Sahil,

      > Static is not an equivalent of Yield.
      Now I see it, probably do I not understand the word "Any" (that word that
      you wrote and now consequently are changing for "an").

      I did not know that in English "any" is an equivalent for "exactly"

      While I did not say, "it is". I wrote that I thought ("think" was what I
      wrote) that it reached that.

      Ah, I see it; "thinking" is probably the same in English as "telling"

      Sorry, I assume that is the problem,

      Thank you for learning me this

      Cor

      corligthert | Wed, 02 Jan 2008 19:07:00 GMT |

    47. Herfried,

      > \\\
      > Private Sub Form1_Activated( _
      > ByVal sender As Object, _
      > ByVal e As EventArgs _
      > ) Handles MyBase.Activated
      > Static IsActivated As Boolean
      > If Not IsActivated Then
      > IsActivated = True
      > Application.DoEvents() ' ...
      > MsgBox("Form activated for the first time!")
      > End If
      > End Sub
      > ///
      For me this is BS (not angry meant only for the discussion). I have even
      seen that people use for this a tag in a control, because it is always
      global, my opinion is than to set it just global. In VB it is that even
      shorter to write if you use "Dim" (what I don't do if it is global) than
      "Static". The technical result is probably (you know that most probably
      better) the same.

      Where I have seen static used nice, was where your friend (Fergus) used in
      to keep track of the last used mouse pointers inside a procedure. That was
      the reason why I direct made a relation to an iterator.

      However it is for me something very special in VB. Therefore I don't like
      it. I have to search that static variable (I don't expect it as static) and
      make than easily the same mistake as Frans made with my sample.

      Cor

      corligthert | Wed, 02 Jan 2008 19:08:00 GMT |

    48. "Cor Ligthert" <notmyfirstname...planet.nl> schrieb:
      >> \\\
      >> Private Sub Form1_Activated( _
      >> ByVal sender As Object, _
      >> ByVal e As EventArgs _
      >> ) Handles MyBase.Activated
      >> Static IsActivated As Boolean
      >> If Not IsActivated Then
      >> IsActivated = True
      >> Application.DoEvents() ' ...
      >> MsgBox("Form activated for the first time!")
      >> End If
      >> End Sub
      >> ///
      >>
      > For me this is BS (not angry meant only for the discussion). I have even
      > seen that people use for this a tag in a control, because it is always
      > global, my opinion is than to set it just global. In VB it is that even
      > shorter to write if you use "Dim" (what I don't do if it is global) than
      > "Static". The technical result is probably (you know that most probably
      > better) the same.

      I feel sorry, but I don't have a cue what you are talking about...

      --
      M S Herfried K. Wagner
      M V P <URL:http://dotnet.mvps.org/>
      V B <URL:http://classicvb.org/petition/>

      herfriedkwagnermvp | Wed, 02 Jan 2008 19:09:00 GMT |

    49. Herfried K. Wagner [MVP] wrote:

      > "Frans Bouma [C# MVP]" <perseus.usenetNOSPAM...xs4all.nl> schrieb:
      > >> > I just wanted to explain that code like you wrote is hard to
      > read, >> > thus not what you want. This was mainly caused by the
      > static >> > keyword. I.o.w.: static is IMHO a keyword you should
      > better avoid >> > (like goto),
      > > >> I disagree. There are certain cases where 'Static' makes perfect
      > >> sense and additionally leads to better-encapsulated code than
      > using a >> private (shared) field. Note that this should not
      > encourage the use >> of 'Static' where it doesn't make much sense ;-).
      > > Now I'm interested in what these situations are. Could you give an
      > > explanation where it will give much BETTER code than when you
      > > wouldn't have the Static keyword?
      > I never said that it will give much better code! One of the Windows
      > Forms FAQs is how to execute certain code only the first time a
      > Windows Forms form is activated. There are many different solutions
      > to the problem which have different advantages and disadvantages.
      > Sure, you could create a private field instead of the static variable
      > below, but I think that a static variable encapsulates the whole
      > functionality more tightly:
      > \\\
      > Private Sub Form1_Activated( _
      > ByVal sender As Object, _
      > ByVal e As EventArgs _
      > ) Handles MyBase.Activated
      > Static IsActivated As Boolean
      > If Not IsActivated Then
      > IsActivated = True
      > Application.DoEvents() ' ...
      > MsgBox("Form activated for the first time!")
      > End If
      > End Sub
      > ///

      Though the 'form' is activated so isn't it more appropriate to simply
      keep a member variable? After all, the data of the activation of the
      form belongs to the form, at least that's my understanding, but that's
      nittpicking about the example. I think in a more procedural
      environment, where the code is stored in a class but you want to run
      the code just one time, not multiple times, and the code can;t really
      rely on the class it is in as the class is just a container of the
      code, it might make sense, but IMHO those situations are pretty rare
      (as in: in an OO world, you can always write the code differently so
      you dont' need it)

      > Today's code often suffers from the problem that private variables
      > holding values used in a method or property semantically belong to a
      > certain method or property, and not to the whole class. For methods
      > this problem can be reduced by using static variables. Similar
      > functionality for properties would be great, for example, something
      > like the code below:
      > \\\
      > Public Property TheFoo() As Foo
      > Dim TheFooValue As Foo
      > Get
      > Return TheFooValue
      > End Get
      > Set(ByVal Value As Foo)
      > TheFooValue = Value
      > End Set
      > End Property
      > ///
      > However, this is currently not supported.

      and rightfully so. properties belong to the semantic unit represented
      by the class to set/get class related (private) fields. All code in a
      class is there because it is behavior belonging to the type(s) the
      class represents and to serve the data the class holds. It requires
      that procedural thinking should take a backseat. Personally I can't
      think of a situation where local scoped data has to be stored in a
      class member because the method ends and it's semantically wrong to
      place the data in a variable outside the method.

      FB

      --
      ----------------------
      Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
      My .NET blog: http://weblogs.asp.net/fbouma
      Microsoft MVP (C#)
      ----------------------

      fransboumacmvp | Wed, 02 Jan 2008 19:10:00 GMT |

    50. Herfried,

      Thats Cor - http://redwing.hutman.net/~mreed/warriorshtm/loopy.htm

      - Sahil Malik [MVP]
      Upcoming ADO.NET 2.0 book - http://tinyurl.com/9bync
      -----------------------
      -----

      "Herfried K. Wagner [MVP]" <hirf-spam-me-here...gmx.at> wrote in message
      news:eVGpjYBeFHA.3808...TK2MSFTNGP14.phx.gbl...
      > "Cor Ligthert" <notmyfirstname...planet.nl> schrieb:
      > >> \\\
      > >> Private Sub Form1_Activated( _
      > >> ByVal sender As Object, _
      > >> ByVal e As EventArgs _
      > >> ) Handles MyBase.Activated
      > >> Static IsActivated As Boolean
      > >> If Not IsActivated Then
      > >> IsActivated = True
      > >> Application.DoEvents() ' ...
      > >> MsgBox("Form activated for the first time!")
      > >> End If
      > >> End Sub
      > >> ///
      > >>
      > > For me this is BS (not angry meant only for the discussion). I have even
      > > seen that people use for this a tag in a control, because it is always
      > > global, my opinion is than to set it just global. In VB it is that even
      > > shorter to write if you use "Dim" (what I don't do if it is global) than
      > > "Static". The technical result is probably (you know that most probably
      > > better) the same.
      > I feel sorry, but I don't have a cue what you are talking about...
      > --
      > M S Herfried K. Wagner
      > M V P <URL:http://dotnet.mvps.org/>
      > V B <URL:http://classicvb.org/petition/

      sahilmalikmvp | Wed, 02 Jan 2008 19:11:00 GMT |

    51. Unfortunately not.

      Mike Ober.

      "Sahil Malik [MVP]" <contactmethrumyblog...nospam.com> wrote in message
      news:%23BJU5d5dFHA.2288...TK2MSFTNGP14.phx.gbl...
      > What the heck - I can't find it. A bit shocked to see it missing though.
      > So "Does VB.NET have the yield keyword, or any equivalent of it" ?
      > --
      > - Sahil Malik [MVP]
      > Upcoming ADO.NET 2.0 book - http://tinyurl.com/9bync
      > -----------------------
      --

      michaeld_ober | Wed, 02 Jan 2008 19:13:00 GMT |

    52. Frans,

      For me it is simple where my problem with static is.

      "A value goes out of scope, when it is instanced inside a procedure and
      there is not a reference from another object to it, when the program leaves
      the procedure".

      The static keyword is for me in conflict with that and because that I find
      that rule so important gives it me not the right feeling.

      Of course is every code allowed, OOP is for me just a method to make it
      clearer and therefore for me the way to go. In addition, that second
      sentence (rule) I wrote is even outside OOP a rule.

      Cor.

      corligthert | Wed, 02 Jan 2008 19:14:00 GMT |

    53. Thanks Michael

      --

      - Sahil Malik [MVP]
      Upcoming ADO.NET 2.0 book - http://tinyurl.com/9bync
      -----------------------
      -----

      "Michael D. Ober" <obermd.....alum.mit.edu.nospam> wrote in message
      news:PlLue.8415$hK3.3835...newsread3.news.pas.earthl ink.net...
      > Unfortunately not.
      > Mike Ober.
      > "Sahil Malik [MVP]" <contactmethrumyblog...nospam.com> wrote in message
      > news:%23BJU5d5dFHA.2288...TK2MSFTNGP14.phx.gbl...
      > > What the heck - I can't find it. A bit shocked to see it missing though.
      > > So "Does VB.NET have the yield keyword, or any equivalent of it" ?
      > > --
      > > - Sahil Malik [MVP]
      > > Upcoming ADO.NET 2.0 book - http://tinyurl.com/9bync
      > -----------------------
      > --

      sahilmalikmvp | Wed, 02 Jan 2008 19:15:00 GMT |

    54. Yall are crazy

      "Cor Ligthert" wrote:

      > Herfried,
      > > Cor, try to keep it outside the groups.
      > As you know I try forever, however sometimes I get angry when the mud is to
      > much.
      > However you are right in this one.
      > If you look at the last replies from Frans than you see what I tried to
      > tell.
      > (The one you have replied now that you disagreed. And do that than because
      > of that as well with me).
      > > "A real man can admit when he makes a mistake."
      > I am not mistaking in this. In my opinion have I nowhere written what you
      > probably think that you read from the answers from others.
      > See my other message to your thread written before I could read this one.
      > Cor
      >
      >

      rob | Wed, 02 Jan 2008 19:16:00 GMT |