473,382 Members | 1,424 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,382 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 911
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.