Newbie: Should I use an array? And how?
-
I am trying to build a small application that collects data about several client applications; it also listens for triggered events and represents them graphically. I have a basic version running ok. I am storing the client info directly into a listview. However I would now like to do other 'clever' things with the collected client info. I was planning to store the data in an array. The problem I have run into is that I do not know the size the array will need to be until I have started to populate it with data. Is there a way to dynamically add data to an array? Or is there another way of storing the client info (so it can be processed and have things done to it)? Thanks in advance... Phil
"Rules are for the obedience of fools and the guidance of wise men"
-
I am trying to build a small application that collects data about several client applications; it also listens for triggered events and represents them graphically. I have a basic version running ok. I am storing the client info directly into a listview. However I would now like to do other 'clever' things with the collected client info. I was planning to store the data in an array. The problem I have run into is that I do not know the size the array will need to be until I have started to populate it with data. Is there a way to dynamically add data to an array? Or is there another way of storing the client info (so it can be processed and have things done to it)? Thanks in advance... Phil
"Rules are for the obedience of fools and the guidance of wise men"
Take a look at the
System.Collections
andSystem.Collections.Generic
namespaces.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
-
Take a look at the
System.Collections
andSystem.Collections.Generic
namespaces.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
Will do... Thanks
"Rules are for the obedience of fools and the guidance of wise men"
-
I am trying to build a small application that collects data about several client applications; it also listens for triggered events and represents them graphically. I have a basic version running ok. I am storing the client info directly into a listview. However I would now like to do other 'clever' things with the collected client info. I was planning to store the data in an array. The problem I have run into is that I do not know the size the array will need to be until I have started to populate it with data. Is there a way to dynamically add data to an array? Or is there another way of storing the client info (so it can be processed and have things done to it)? Thanks in advance... Phil
"Rules are for the obedience of fools and the guidance of wise men"
In .NET 1.1 try ArrayList. In .NET 2.0 try List.
Kevin
-
I am trying to build a small application that collects data about several client applications; it also listens for triggered events and represents them graphically. I have a basic version running ok. I am storing the client info directly into a listview. However I would now like to do other 'clever' things with the collected client info. I was planning to store the data in an array. The problem I have run into is that I do not know the size the array will need to be until I have started to populate it with data. Is there a way to dynamically add data to an array? Or is there another way of storing the client info (so it can be processed and have things done to it)? Thanks in advance... Phil
"Rules are for the obedience of fools and the guidance of wise men"
-
I am trying to build a small application that collects data about several client applications; it also listens for triggered events and represents them graphically. I have a basic version running ok. I am storing the client info directly into a listview. However I would now like to do other 'clever' things with the collected client info. I was planning to store the data in an array. The problem I have run into is that I do not know the size the array will need to be until I have started to populate it with data. Is there a way to dynamically add data to an array? Or is there another way of storing the client info (so it can be processed and have things done to it)? Thanks in advance... Phil
"Rules are for the obedience of fools and the guidance of wise men"
Ahh now this sound like my kind of tool. I planned on writing something similar once to graphically map transactions as they moved through BizTalk. When you use an ArrayList or List<> the structure is such that an initial size is created and dynamically grows as you add additional items. It is better in the performance department if you generally know how many items will go into the array, but it is not a necessity. You can also deploy custom dictionaries as well so you may want to do something like this: Applications go into a List (all the applications inherit the same interface making it easy to store different programs but treat them as the same type) Application fires a trigger event Listener (your code) plots that event but also adds to a Dictionary ReceivedEventEventHandler(object sender, ListenerEventArgs e)
{
ICommunicator details = (ICommunicator)sender;
PlotEvent(details.Name, e.EventObject);
dictionary[details.Name].Add(e);
}Now you can expose a menu selection to show historical event data for any program in the list, trending across applications, frequency of events across time, and other fun statistical stuff.