Click here to Skip to main content
15,896,154 members
Home / Discussions / C#
   

C#

 
QuestionCount Array Items with C# Pin
BenjaminMartin29-Jun-07 3:55
BenjaminMartin29-Jun-07 3:55 
AnswerRe: Count Array Items with C# Pin
Luc Pattyn29-Jun-07 4:28
sitebuilderLuc Pattyn29-Jun-07 4:28 
GeneralRe: Count Array Items with C# Pin
BenjaminMartin29-Jun-07 4:53
BenjaminMartin29-Jun-07 4:53 
GeneralRe: Count Array Items with C# Pin
leppie29-Jun-07 4:54
leppie29-Jun-07 4:54 
AnswerRe: Count Array Items with C# Pin
Guffa29-Jun-07 4:47
Guffa29-Jun-07 4:47 
AnswerRe: Count Array Items with C# Pin
leppie29-Jun-07 4:52
leppie29-Jun-07 4:52 
GeneralRe: Count Array Items with C# Pin
BenjaminMartin29-Jun-07 5:10
BenjaminMartin29-Jun-07 5:10 
AnswerRe: Count Array Items with C# Pin
Kevin McFarlane29-Jun-07 6:10
Kevin McFarlane29-Jun-07 6:10 
Apart from leppie's solution you might want to have a look at the free PowerCollections library.

PowerCollections[^]

Then you can do:

int[] array = new int[10];
array[0] = 1;
array[1] = 1;
array[2] = 1;
array[3] = 2;
array[4] = 1;
array[5] = 2;
array[6] = 1;
array[7] = 1;
array[8] = 2;
array[9] = 3;

int count1 = Algorithms.CountWhere(array, delegate(int i) { return i == 1; });
Console.WriteLine("Count = {0}", count1);
int count2 = Algorithms.CountWhere(array, delegate(int i) { return i == 2; });
Console.WriteLine("Count = {0}", count2);
int count3 = Algorithms.CountWhere(array, delegate(int i) { return i == 3; });
Console.WriteLine("Count = {0}", count3);


PowerCollections consists of additional data structures and algorithms, somewhat similar to C++'s STL. It's very easy to use. Just reference the DLL and add a using statement. It was written by a former member of the C# team and went though quite a lot of beta testing. There is another possibly more advanced library called C5, which I've never used.



Kevin

Questionndoc MSDN style document Pin
Software_Specialist29-Jun-07 3:36
Software_Specialist29-Jun-07 3:36 
AnswerRe: ndoc MSDN style document Pin
BoneSoft29-Jun-07 3:49
BoneSoft29-Jun-07 3:49 
GeneralRe: ndoc MSDN style document Pin
Software_Specialist29-Jun-07 3:54
Software_Specialist29-Jun-07 3:54 
GeneralRe: ndoc MSDN style document Pin
Kevin McFarlane29-Jun-07 6:14
Kevin McFarlane29-Jun-07 6:14 
GeneralRe: ndoc MSDN style document Pin
Software_Specialist1-Jul-07 22:58
Software_Specialist1-Jul-07 22:58 
GeneralRe: ndoc MSDN style document Pin
Kevin McFarlane2-Jul-07 1:07
Kevin McFarlane2-Jul-07 1:07 
GeneralRe: ndoc MSDN style document Pin
BoneSoft29-Jun-07 6:14
BoneSoft29-Jun-07 6:14 
QuestionCreate/Fill Datatable Pin
tadhg8829-Jun-07 3:23
tadhg8829-Jun-07 3:23 
AnswerRe: Create/Fill Datatable Pin
Not Active29-Jun-07 3:27
mentorNot Active29-Jun-07 3:27 
GeneralRe: Create/Fill Datatable Pin
tadhg8829-Jun-07 3:45
tadhg8829-Jun-07 3:45 
QuestionMSMQ Send Error Pin
ramdil29-Jun-07 2:46
ramdil29-Jun-07 2:46 
AnswerRe: MSMQ Send Error Pin
originSH29-Jun-07 3:05
originSH29-Jun-07 3:05 
GeneralRe: MSMQ Send Error Pin
ramdil29-Jun-07 3:43
ramdil29-Jun-07 3:43 
Questionplace program icon into desktop toolbox Pin
iman_kh29-Jun-07 2:12
iman_kh29-Jun-07 2:12 
AnswerRe: place program icon into desktop toolbox Pin
giddy_guitarist29-Jun-07 3:45
giddy_guitarist29-Jun-07 3:45 
GeneralRe: place program icon into desktop toolbox Pin
iman_kh29-Jun-07 5:06
iman_kh29-Jun-07 5:06 
QuestionNothing and null Pin
Brendan Vogt29-Jun-07 2:08
Brendan Vogt29-Jun-07 2:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.