473,412 Members | 2,012 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 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 914
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Steven Bethard | last post by:
I have a list of dictionaries. Each dictionary holds counts of various 'words', e.g.: py> countdicts = I need to select dicts with the constraint that the number of each 'word' totalled...
0
by: Andres | last post by:
Hi, i have this questions: 1 - How can i create user counts in Windows with C#? 2 - How can i set permissions for the counts with C#? 3 - How can i start an application with one of the created...
3
by: Torsten Wiebesiek | last post by:
Hi, I am currently working on a computer vision system. At the moment I'm adding support for firewire cameras. Since there is only one firewire system on a computer, I have writen a firewire...
5
by: WertmanTheMad | last post by:
Ive been playing with this for a few days and thought I might thow it out for seggestions. I have Several Queries that need counts returned The Queries are Mutually Exclusive meaning whatever...
4
by: cantabile | last post by:
Hi, I have a class (a gui) with buttons and other controls. A button, for example, has a callback method, so that writing b = Button(label, OnClick) will call the global OnClick method. ...
7
by: tgh003 | last post by:
I would be interested to hear how others are managing their javascript (.js) files from the original code vs the obfuscated version they publish to their site/webapp. I currently manage 2 files,...
1
by: Randy K | last post by:
I have a table with some 35000 records and I need some help sorting it out. The goal is to get counts of failures modes oraganized by serial number. the table is set up roughly like this. s/n ...
2
by: fariba123 | last post by:
i have designed an employee information site. there is an option to generate pay slip. how can i show the employee related data based on the drop down list. i have found code example for...
3
by: Wildster | last post by:
Hi, How can you count x and y as seperate counts from the same field? i.e. A table has the field Gender and I want to have one count which counts the number of records with 'male' as the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.