473,320 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

need an iterable collection which repeats or cycles its values

Hi, I wrote a Forms program which toggles a label each time you click
it:
private void button1_Click(object sender, EventArgs e)
{
label1.Text = (label1.Text == "hello") ? "goodbye" :
"hello" ;
}

but in the interest of scaleability, I want this program to store the
label values in a collection, access them via Next() and cycle back to
the beginning when the end of the collection is reached.

Any pointers to something in the .NET library which allows this?

Jul 26 '06 #1
4 1639
metaperl wrote:
Hi, I wrote a Forms program which toggles a label each time you click
it:
private void button1_Click(object sender, EventArgs e)
{
label1.Text = (label1.Text == "hello") ? "goodbye" :
"hello" ;
}

but in the interest of scaleability, I want this program to store the
... very enterprisey ;)
label values in a collection, access them via Next() and cycle back to
the beginning when the end of the collection is reached.

Any pointers to something in the .NET library which allows this?
I don't think there is such a collection in the .NET library. You'll
probably have to create your own custom collection.

Besides only adding the label values you could also add delegates to the
collection. This way you could create a method Execute() which executes
the Method associated with the current label.

Max
Jul 26 '06 #2
Well there certainly is a datastructure that can do just this. A queue
Queue<stringfoo = new Queue<string>();
foo.Enqueue("Hello");
foo.Enqueue("Hello2");
foo.Enqueue("Hello3");
then whenever you need a string you simply use

string s = foo.Dequeue();
foo.Enqueue(s);
This will provide your wrap around functionality for you.

Cheers,

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung
"Markus Stoeger" <sp******@gmx.atwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
metaperl wrote:
>Hi, I wrote a Forms program which toggles a label each time you click
it:
private void button1_Click(object sender, EventArgs e)
{
label1.Text = (label1.Text == "hello") ? "goodbye" :
"hello" ;
}

but in the interest of scaleability, I want this program to store the

.. very enterprisey ;)
>label values in a collection, access them via Next() and cycle back to
the beginning when the end of the collection is reached.

Any pointers to something in the .NET library which allows this?

I don't think there is such a collection in the .NET library. You'll
probably have to create your own custom collection.

Besides only adding the label values you could also add delegates to the
collection. This way you could create a method Execute() which executes
the Method associated with the current label.

Max

Jul 26 '06 #3
Greg Young wrote:
Well there certainly is a datastructure that can do just this. A queue
Queue<stringfoo = new Queue<string>();
foo.Enqueue("Hello");
foo.Enqueue("Hello2");
foo.Enqueue("Hello3");
then whenever you need a string you simply use

string s = foo.Dequeue();
foo.Enqueue(s);
This will provide your wrap around functionality for you.
If we were being polite, we would of course wrap this 'bizarro queue' in
a class called CyclicList<T>, wouldn't we... :)
--
Larry Lard
la*******@googlemail.com
The address is real, but unread - please reply to the group
For VB and C# questions - tell us which version
Jul 27 '06 #4
haha .. yes that we would .. ah the life of a maintenance programmer.

Although I do have a certain fondness for BizarroQueue .. perhaps I would
make it add to the head occasionally too to make it truely bizarre.

"Larry Lard" <la*******@googlemail.comwrote in message
news:4i************@individual.net...
Greg Young wrote:
>Well there certainly is a datastructure that can do just this. A queue
Queue<stringfoo = new Queue<string>();
foo.Enqueue("Hello");
foo.Enqueue("Hello2");
foo.Enqueue("Hello3");
then whenever you need a string you simply use

string s = foo.Dequeue();
foo.Enqueue(s);
This will provide your wrap around functionality for you.

If we were being polite, we would of course wrap this 'bizarro queue' in a
class called CyclicList<T>, wouldn't we... :)
--
Larry Lard
la*******@googlemail.com
The address is real, but unread - please reply to the group
For VB and C# questions - tell us which version

Jul 27 '06 #5

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

Similar topics

6
by: Jani Yusef | last post by:
I have a HW problem stated as shown at the top of the solution. The thing is is that I am not 100% sure wtf constant memory means. Well, I think I do but I am confused. Does my solution use contant...
1
by: Joh | last post by:
hello, thanks to all who replied to my post (2005-01-21) - (i can not post inside the original thread as i get "Unable to retrieve message csr7ep$3db$05$1@news.t-online.com" from googlenews :( ...
4
by: Michele Simionato | last post by:
According to the standand library (http://docs.python.org/lib/typeiter.html) an *iterable* is something with an __iter__ method. This means that strings are *not* iterable. However I can loop...
4
by: Pedro Miguel Carvalho | last post by:
Greetings. I'm creating a project that as a intricate relation between object kind of like a set where each object in the set can be connect to a subset of object of the set and objects not in...
5
by: Richard | last post by:
Hi, I'm writing an MS Outlook 2000 Addin in C#. I have created C# classes that monitor folder events and do other business logic. Things work fine until I want to exit Outlook. When I exit...
70
by: py | last post by:
I have function which takes an argument. My code needs that argument to be an iterable (something i can loop over)...so I dont care if its a list, tuple, etc. So I need a way to make sure that...
2
by: Benjamin Johnston | last post by:
Hi, I've found lots of discussion about the JavaScript garbage collector, but no clear answer to this question: Is the garbage collection algorithm used in JavaScript on ASP based on...
17
by: andreas.eisele | last post by:
I should have been more specific about possible fixes. In a related thread on http://bugs.python.org/issue2607 Amaury Forgeot d'Arc suggested a setting of the GC thresholds that actually...
13
by: Kurda Yon | last post by:
Hi, I found one example which defines the addition of two vectors as a method of a class. It looks like that: class Vector: def __add__(self, other): data = for j in range(len(self.data)):...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.