Reputation: 55
So at the moment I have a multidimensional array
string[,] items = new string[100, 4];
I then gather the needed inputs to put them into the array, and then display them in a listbox
items[itemcount, 0] = id;
items[itemcount, 1] = newprice;
items[itemcount, 2] = quant;
items[itemcount, 3] = desc;
listBox1.Items.Add(items[itemcount, 0] + "\t" + items[itemcount, 3] + "\t " + items[itemcount, 2] + "\t " + items[itemcount, 1]);
listBox1.SelectedIndex = listBox1.Items.Count - 1;
So then the user can if they want select an item from the listbox to delete that item. When it came to deleting an item I realized that an array is not suitable. So should I create 4 different lists and use the list.Remove method to delete them or is there a better way that I dont have to work on 4 different things, also the user is running an older computer with WinXP would i have to worry about performance with 4 different lists? Is there anything such as a multidimensional list?
Thanks heaps for your help
Upvotes: 3
Views: 118
Reputation: 3665
It looks like you have one complex type, that you should put into a list. Not sure if the names are right, but something like this looks like what you want.
public class InventoryEntry
{
public string Id {get;set;}
public double NewPrice {get;set;}
public int Quantity {get;set;}
public string Description {get;set;}
public override ToString()
{
//return your specially formatted string here
}
}
var items = new List<InventoryEntry>();
//add some items
//add them to your listbox
//etc...
Upvotes: 2
Reputation: 100547
You are trying to reinvent List of instances of a class. Something like
class Item {
public int Id {get;set;}
public double Price {get;set;}
public double Quantity {get;set;}
public string Description {get;set;}
}
var myItems = new List<Item>();
Upvotes: 7
Reputation: 32604
With the amount of data you'll be working with you really shouldn't see any performance issues.
Any type of Collection whether it be a List<T>
, Dictionary<T, T>
, IEnumerable<T>
, or whatever you want to use, it will provide you with more functionality than an array will.
Upvotes: 3