Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
-How can i array of random numbers that represent the dice index ?
-loop take 10 numbers
-save the random numbers in array or use an array list(better)
-use list box to show the 10 random saved numbers

****************************

another side question.

How can I pass from form into another ?
What if I want to add a timer for the dice app ?

P.s: it’s very important for me to know the solution 
thanks in advance.


What I have tried:

I was trying it since a week and i did not reach any goal

Private random die = new random();

For(int i=0; i<5; i++)}
Die[i]=i;
}

HERE THE PROBLEM IS HOW CAN I ADD IT TO ARRAY IF I DONT USE ARRAYLIST
AND IM SO CONFUSED :(
Posted
Updated 18-Mar-17 23:41pm
v2
Comments
OriginalGriff 19-Mar-17 5:02am    
DON'T SHOUT. Using all capitals is considered shouting on the internet, and rude (using all lower case is considered childish). Use proper capitalization if you want to be taken seriously.
Member 13068795 19-Mar-17 5:21am    
Sorry I did not mean it. Thanks for this information ... Really I did not know it .
I Wish that you can help me.
OriginalGriff 19-Mar-17 5:27am    
Why would I?
You are still shouting at us.
And you clearly did know, as your title was in "proper case" and everything else was SHOUTY.

1 solution

Quote:
-How can i array of random numbers that represent the dice index ?
-loop take 10 numbers
-save the random numbers in array or use an array list(better)

If you are trying to fill an array with random numbers that represent dice rolls, then that's simple:
C#
private Random die = new Random();
...
int[] rolls = new int[10];
for (int i = 0; i < rolls.Length; i++)
   {
   rolls[i] = die.Next(6) + 1;
   }
Don't use ArrayList - it'a very, very out of date. There are better constructs called Generic Collections which are much easier to use:
List<int> rolls = new List<int>();
for (int i = 0; i < 10; i++)
    {
    rolls.Add(die.Next(6) + 1);
    }
With generic collections you don;t have to cast teh values to a particular datatype when you try to use them, and the system enforces that you can only put the right type of data in them.
Quote:
-use list box to show the 10 random saved numbers

myListBox.DataSource = rolls;


Quote:
How can I pass from form into another ?

That is complicated: it depends on a lot of factors, and it probably outside your knowledge set at the moment - you really need to get basic stuff like this well and truly sorted before you start wading into the complex stuff.
But...
Transferring information between two forms, Part 1: Parent to Child[^]
Transferring information between two forms, Part 2: Child to Parent[^]
Transferring information between two forms, Part 3: Child to Child[^]
Quote:
What if I want to add a timer for the dice app ?
            System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
            timer.Interval = 1000;
            timer.Tick += timer_Tick;
            timer.Start();
...
        void timer_Tick(object sender, EventArgs e)
            {
            // Do your timer stuff here.
            }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900