471,330 Members | 1,132 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,330 software developers and data experts.

managing counts

Hi
I need to manage count as follows:

MainItem1 SubItem1 - 10
MainItem1 SubItem2 - 5
MainItem1 SubItem3 - 10
MainItem2 SubItem1 - 15
MainItem3 SubItem1 - 10
MainItem3 SubItem2 - 9

what would be the best datastructure to store such data.?

Thanks in advance
Regards
ArunDhaJ
Jun 27 '08 #1
3 866
ArunDhaJ,

You could always create a structure with two fields, MainItem and
SubItem, then use that as a key in a dictionary, where the value is an int.

Then, you can just add to the value in the dictionary as you come across
your fields.

Of course, if you are using LINQ, you could easily query your collection
and group on MainItem and SubItem and select the count for each group.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"ArunDhaJ" <ar******@gmail.comwrote in message
news:37**********************************@k30g2000 hse.googlegroups.com...
Hi
I need to manage count as follows:

MainItem1 SubItem1 - 10
MainItem1 SubItem2 - 5
MainItem1 SubItem3 - 10
MainItem2 SubItem1 - 15
MainItem3 SubItem1 - 10
MainItem3 SubItem2 - 9

what would be the best datastructure to store such data.?

Thanks in advance
Regards
ArunDhaJ

Jun 27 '08 #2
Thanks Nicholas, I'm using C# 2.0.
After storing the key and value how can we query the dictionary to get
the total counts for individual Items. From the example in previous
posts, I need to get the total count of MainItem1 as 25, MainItem2 as
15 and MainItem3 as 19.
Thanks in advance

-ArunDhaJ
On Jun 4, 10:07*pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
ArunDhaJ,

* * You could always create a structure with two fields, MainItem and
SubItem, then use that as a key in a dictionary, where the value is an int..

* * Then, you can just add to the value in the dictionary as you come across
your fields.

* * Of course, if you are using LINQ, you could easily query your collection
and group on MainItem and SubItem and select the count for each group.

--
* * * * * - Nicholas Paldino [.NET/C# MVP]
* * * * * - m...@spam.guard.caspershouse.com

"ArunDhaJ" <arund...@gmail.comwrote in message

news:37**********************************@k30g2000 hse.googlegroups.com...
Hi
I need to manage count as follows:
MainItem1 SubItem1 - 10
MainItem1 SubItem2 - 5
MainItem1 SubItem3 - 10
MainItem2 SubItem1 - 15
MainItem3 SubItem1 - 10
MainItem3 SubItem2 - 9
what would be the best datastructure to store such data.?
Thanks in advance
Regards
ArunDhaJ- Hide quoted text -

- Show quoted text -
Jun 27 '08 #3
Well, you are going to have to cycle through all of the items, and
increment the value in the dictionary one at a time as you come across the
MainItem/SubItem combinations. As you cycle through every item (when
generating the count), if the key exists, then get the value, increment by
one, and then set the value back.

If the key doesn't exist, insert one for that key into the dictionary.

- Nick

"ArunDhaJ" <ar******@gmail.comwrote in message
news:be**********************************@k30g2000 hse.googlegroups.com...
Thanks Nicholas, I'm using C# 2.0.
After storing the key and value how can we query the dictionary to get
the total counts for individual Items. From the example in previous
posts, I need to get the total count of MainItem1 as 25, MainItem2 as
15 and MainItem3 as 19.
Thanks in advance

-ArunDhaJ
On Jun 4, 10:07 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
ArunDhaJ,

You could always create a structure with two fields, MainItem and
SubItem, then use that as a key in a dictionary, where the value is an
int.

Then, you can just add to the value in the dictionary as you come across
your fields.

Of course, if you are using LINQ, you could easily query your collection
and group on MainItem and SubItem and select the count for each group.

--
- Nicholas Paldino [.NET/C# MVP]
- m...@spam.guard.caspershouse.com

"ArunDhaJ" <arund...@gmail.comwrote in message

news:37**********************************@k30g2000 hse.googlegroups.com...
Hi
I need to manage count as follows:
MainItem1 SubItem1 - 10
MainItem1 SubItem2 - 5
MainItem1 SubItem3 - 10
MainItem2 SubItem1 - 15
MainItem3 SubItem1 - 10
MainItem3 SubItem2 - 9
what would be the best datastructure to store such data.?
Thanks in advance
Regards
ArunDhaJ- Hide quoted text -

- Show quoted text -

Jun 27 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Steven Bethard | last post: by
reply views Thread by Andres | last post: by
3 posts views Thread by Torsten Wiebesiek | last post: by
4 posts views Thread by cantabile | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.