473,395 Members | 1,978 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,395 software developers and data experts.

Counting instances in c# (keeping a tally)

6
Hi,

I am reading a database which is returning a list of dates. I need to count the instances of each date and store in an array or similar.
I don't know how many dates I will be getting, or how many different ones.

In Perl I would so something like this
for(`getdata`){
$array{$1}++;
}

need something that looks like this:

while (dReader.Read())
{
Array['dReader[0].ToString()']++;
}


Any ideas?
Apr 9 '08 #1
3 1268
r035198x
13,262 8TB
Hi,

I am reading a database which is returning a list of dates. I need to count the instances of each date and store in an array or similar.
I don't know how many dates I will be getting, or how many different ones.

In Perl I would so something like this
for(`getdata`){
$array{$1}++;
}

need something that looks like this:

while (dReader.Read())
{
Array['dReader[0].ToString()']++;
}


Any ideas?
You could use a System.Collections.Hashtable<DateTime, int>.
Apr 9 '08 #2
trd79
6
You could use a System.Collections.Hashtable<DateTime, int>.
Many thanks,

will try that.
Apr 9 '08 #3
trd79
6
Hi,

Have tried using a hashtable as suggested.

Currently looks like this (and seems to work)

Expand|Select|Wrap|Line Numbers
  1. Hashtable sessions = new Hashtable();
  2. while (dReader.Read())
  3.         {
  4.             DateTime date = DateTime.Parse(dReader[0].ToString());
  5.             sessions[date] = (sessions.ContainsKey(date)) ? (int)sessions[date] + 1 : 1;
  6.         }
Is this the best way of doing it?
Apr 14 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Lizard | last post by:
OK, total newbie here, so this may be a mind-numbingly dumb question AND I may be phrasing it badly. I have an xsl:template which looks like this: <xsl:template match="LoanRecord"> <hr>...
6
by: Ronald | last post by:
Hi there, I would like to challenge you all to make the fastest tally-function possible. The function should count the number of times a specified string is present within another string. As I'm...
4
by: Chad Myers | last post by:
I'm instrumenting my app with a few performance counters and I'd like to ask you all for some advice on how to handle performance counter instances. I have a class library that is a base library...
1
sheenattt
by: sheenattt | last post by:
Hello all, How can I use Tally in .Net?I want to map Tally to web based application,means is it possible to click a link and we can import or export tally to web.I want to put authentication also...
1
by: Hypnotik | last post by:
Well on to my next program. The program tally's votes on 3 issues. I have a class for the interface (asks questions) and a class for adding the tallies. In main there is a counter of Tally data...
3
by: pub | last post by:
Hello..im a junior programmer( a beginner) in .NET C#..... so i really dono hw to use tally 9...so plzzzzz witot any set bak help me in learning n handling tally 9......plzzzz provide me de links...
9
by: sathikbasha | last post by:
hi Please help me !!!!!!! how to connect the Tally from VB. Is there any ODBC connection in Tally Software. I need to import the data from SQL Server to Tally. regards
4
by: shailendraedreamz | last post by:
Hi, As in .Net we can connect to Oracle database using OracleClient Name Space. In the same manner can we connect to Tally database directly. Is .Net have provided such facility??
5
by: dugdug | last post by:
I need a function that will count how many times a user clicks a certain control. For an example, there is a button that randomly displays 1 of 4 messages in a text box. I want another label to...
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: 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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.