4 Replies - 749 Views - Last Post: 13 November 2009 - 08:36 AM Rate Topic: -----

#1 Timmeh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 10-November 09

C# ArrayList Question

Posted 10 November 2009 - 07:16 AM

				ArrayList lstNumbers = new ArrayList();
				Random rndNumber = new Random();
				int number = rndNumber.Next(1, max + 1);
				lstNumbers.Add(number);
				int count = 0;

				do
				{
					number = rndNumber.Next(1, max + 1);
					if (!lstNumbers.Contains(number))
					{
						lstNumbers.Add(number);
					}
					count++;
				}
				while (count <= 10 * max);
				{
				}
				return lstNumbers;


I am trying to read through the ArrayList i just made but everytime i read through it with :
public void knop3_Click(object sender, EventArgs e)
		{

			int volgnummer = 0;
			lstNumbers = nbs.RandomNumbers(total);
			if (volgnummer < lstNumbers.Count)
			{
				listBox3.Items.Add(lstNumbers[volgnummer]);
				volgnummer++;
			}
		}


it wont properly follow the ArrayList Properly but if i would use the following :
		  
 lstNumbers = nbs.RandomNumbers(total);
			for (int p = 0; p < lstNumbers.Count; p++)
				listBox1.Items.Add(lstNumbers[p]);



If i use the for function it will generate the 10 randomnumbers without duplicates.
But if i would use the button Click it will put the ArrayList Numbers in a different position and it will make duplicate numbers in the listbox3 maybe i am doing something silly i am still a beginner :)

Any help is appriciated

- Tim

Is This A Good Question/Topic? 0
  • +

Replies To: C# ArrayList Question

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5666
  • View blog
  • Posts: 22,509
  • Joined: 23-August 08

Re: C# ArrayList Question

Posted 10 November 2009 - 07:22 AM

Wrong forum. Moving to C#.
Was This Post Helpful? 0
  • +
  • -

#3 Timmeh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 10-November 09

Re: C# ArrayList Question

Posted 12 November 2009 - 12:39 AM

bump

Sorry for posting in wronge forum before but i pressed the C# Help link so must have send me to the wronge place problem still has not been solved any feedback would be nice
Was This Post Helpful? 0
  • +
  • -

#4 Momerath  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 809
  • View blog
  • Posts: 1,946
  • Joined: 04-October 09

Re: C# ArrayList Question

Posted 12 November 2009 - 08:27 AM

What's nbs.RandomNumbers(total);

You also have a mix of variables that are undefined in the code you provide, which makes it hard to tell what they are, or where they come from.
Was This Post Helpful? 0
  • +
  • -

#5 djkitt  Icon User is offline

  • D.I.C Head

Reputation: 29
  • View blog
  • Posts: 189
  • Joined: 22-May 08

Re: C# ArrayList Question

Posted 13 November 2009 - 08:36 AM

So,

You could try changing:

			if (volgnummer < lstNumbers.Count)
			{




to:
			while (volgnummer < lstNumbers.Count)
			{

//emphasis on the while



Hope this helps,

Kitt
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1