473,889 Members | 1,927 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Yield Keyword in VB.NET 2.0

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
----------------------------------------------------------------------------
Nov 21 '05
54 6949
"Cor Ligthert" <no************ @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/>
Nov 21 '05 #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#)
------------------------------------------------------------------------
Nov 21 '05 #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#)
------------------------------------------------------------------------
Nov 21 '05 #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
Nov 21 '05 #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" <no************ @planet.nl> wrote in message
news:eU******** ******@TK2MSFTN GP10.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

Nov 21 '05 #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" <no************ @planet.nl> wrote in message
news:ep******** ********@TK2MSF TNGP14.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

Nov 21 '05 #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]" <hi************ ***@gmx.at> wrote in message
news:eb******** ********@TK2MSF TNGP14.phx.gbl. ..
"Cor Ligthert" <no************ @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/>

Nov 21 '05 #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]" <pe************ ******@xs4all.n l> wrote in message
news:xn******** *******@news.mi crosoft.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#)
------------------------------------------------------------------------

Nov 21 '05 #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
Nov 21 '05 #29
> or any equivalent of it" ?

"Sahil Malik [MVP]" <co************ *****@nospam.co m> schreef in bericht
news:ur******** ******@tk2msftn gp13.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
----------------------------------------------------------------------------

Nov 21 '05 #30

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

54
2739
by: Sahil Malik [MVP] | last post by:
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 Upcoming ADO.NET 2.0 book - http://tinyurl.com/9bync ----------------------------------------------------------------------------
3
6942
by: Ehsan | last post by:
hi coulde any one show me the usage of "yield" keyword specially in this example: """Fibonacci sequences using generators This program is part of "Dive Into Python", a free Python book for experienced programmers. Visit http://diveintopython.org/ for the latest version.
0
9969
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
9810
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11203
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10896
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10443
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7151
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6029
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4650
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4251
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.