Jedhi Posted February 28, 2005 Posted February 28, 2005 I have created a hashtable class with key id and 3 values id, column and error. _hashtable.Add(id,new object[3]{id,column,Error}); To get information about the id and how many Errors the id have, I write Info = (object[])((ArrayList) _hashtable[id])[0]; int _theIdError = (int)Info[2]; _theIdError++ Now the hashtable must be updated to contain the lastest number of errors (_theIdError) for the specific id. How do I do that ????? Quote
IngisKahn Posted February 28, 2005 Posted February 28, 2005 Instead of using an object array you should think about creating a small class (struct if you're using .NET 2.0 with generics). That way it's only a matter of setting a class member once you get the ref. Quote "Who is John Galt?"
Jedhi Posted February 28, 2005 Author Posted February 28, 2005 Instead of using an object array you should think about creating a small class (struct if you're using .NET 2.0 with generics). That way it's only a matter of setting a class member once you get the ref. Could you give me an example ? Remember that I have 1 key and 3 values. Quote
IngisKahn Posted February 28, 2005 Posted February 28, 2005 [CS]class ErrorInfo { int Id, Column, Errors; public ErrorInfo(int id, int column, int errors) { Id = id; Column = column; Errors = errors; } } ... _hashtable.Add(id,new ErrorInfo(id,column,Error)); ... ErrorInfo Info = (ErrorInfo)_hashtable[id]; Info.Errors++;[/CS] Quote "Who is John Galt?"
Tygur Posted February 28, 2005 Posted February 28, 2005 While it does look like IngisKahn's idea will work, I'd like to let you know that you can stick with the array if you want. If this is really how you added the information to the Hashtable: _hashtable.Add(id,new object[3]{id,column,Error}); Then you can increment that third array element for a specific id with something like this: Object[] Info = (object[])_hashtable[id]; Info[2] = (int)Info[2] + 1; With that said, I would also recommend using your own objects as values in the hashtable instead of arrays. (in other words, this post is just fyi; IngisKahn's suggestion is better) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.