Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Alternative to 2-dimension array that needs to get larger? 1

Status
Not open for further replies.

Amesville

Programmer
Oct 10, 2011
93
0
0
US
Hi Folks

OK so I'm working on an application where I move data around from one text box to another, and part of what I need to do is keep a record of what data moved from one TextBox to the other.

Since I come from a VB background I figured I would just create a 2-dimensional array and store the Data Text, Starting Box and Ending box as such: X,0 = Data Text, X,1 = Starting Box, X,2 = Ending box where X is the first dimension of the array. To add 'records' I would just ReDim the array and add onto it.

But as I've recently learned you cannot easily (if at all) redimension a multidimensional array in C#. I could simply declare that array to hold the maximum number of possible moves and just deal with the memory overhead, but I'd rather learn something.

I thought about trying to use the ListOf<I> collection but this does not seem to allow more than one value per line. Likewise a Hash Table is just a key/value type of thing.

Any thoughts on what I could do with this? I suppose I could just use a hashtable with one string per unique key that has comma-separated values for the rest of the data, but is there another better option I have not yet discovered?

Thanks

Craig
 
A list is just a list of objects be those objects simple or complex. How about a basic class to maintain your manipulated/moved data and a collection of those as a list?

Sorry, c#...

Code:
public class Dummy
{
	public int Id { get; set; }
	public string TextContent { get; set; }
	public TextBox SourceControl { get; set; }	// This could just as easily be a string of the Source Control Id
	public TextBox DestinationControl { get; set; }	// This could just as easily be a string of the Source Control Id	
}

ListOf<Dummy>


Rhys

"Technological progress is like an axe in the hands of a pathological criminal"
"Two things are infinite: the universe and human stupidity; and I'm not sure about the the universe"
Albert Einstein
 
As a predominately VB programmer, I rarely use ReDim or ReDim Preserve and use methods similar to Rhys's suggestion. In this case a class to hold the source and destination objects with other info as appropriate and each instance of the class stored in a List.
 
Thanks Rhys,

I jad actually started out by trying to define a class as you suggested but I hadn't put together being able to use the ListOf collection like that. I should have seen that myself. Thanks for the slap to the head!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top