Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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 ?????

Posted
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.
"Who is John Galt?"
Posted
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.

Posted

[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]

"Who is John Galt?"
Posted

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)

  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...