Wrox Programmer Forums
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 1st, 2007, 04:10 PM
Authorized User
 
Join Date: Jul 2006
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default c

thanks
 
Old April 2nd, 2007, 08:12 AM
Authorized User
 
Join Date: Mar 2007
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Code:
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            Random rand = new Random();
            int[] array = new int[100];
            for (int i = 0; i < 100; i++)
            {
                array[i] = rand.Next(0, 30);
            }

            Dictionary<int, int> counts = new Dictionary<int, int>();
            foreach (int num in array)
            {
                if (counts.ContainsKey(num))
                    counts[num]++;
                else
                    counts.Add(num, 1);
            }

            foreach (KeyValuePair<int, int> kvp in counts)
            {
                Console.WriteLine("there are {0} number of {1}", kvp.Value, kvp.Key);
            }

            Console.ReadLine();
        }
    }
}
 
Old April 2nd, 2007, 08:30 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

<sarcasm>
Literally speaking, each "element" of any array occurs only once.
</sarcasm>

-Peter
 
Old April 3rd, 2007, 04:31 AM
Authorized User
 
Join Date: Jul 2006
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks dafl00 very much for the solution

rao965










Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.